Skip to content

Commit 3539a56

Browse files
jorgepilotopyansys-ci-botRevathyvenugopal162
committed
fix: static search performance (#525)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Revathy Venugopal <[email protected]> Co-authored-by: Revathyvenugopal162 <[email protected]>
1 parent 40d6765 commit 3539a56

File tree

12 files changed

+321
-328
lines changed

12 files changed

+321
-328
lines changed

doc/changelog.d/525.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: static search performance

doc/source/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@
6868
},
6969
"logo": "ansys",
7070
"static_search": {
71-
"threshold": 0.5,
72-
"ignoreLocation": True,
71+
"threshold": 0.2,
72+
"limit": 7,
73+
"minMatchCharLength": 3,
7374
},
7475
}
7576

doc/source/user-guide/options.rst

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,41 +111,50 @@ If you want to hide all icons, use the ``show_icons`` Boolean variable:
111111
Static search options
112112
----------------------
113113

114-
The Ansys Sphinx theme supports static search options to customize the search experience.
114+
The Ansys Sphinx theme supports static search options to customize the search
115+
experience.
115116

116-
The static search bar is created using ``Fuse.js``. You can provide all options supported by ``Fuse.js`` through the ``static_search`` dictionary in the ``html_theme_options``.
117+
The static search bar is created using ``Fuse.js``. You can provide `all
118+
options <https://www.fusejs.io/api/options.html>`_ supported by ``Fuse.js``
119+
through the ``static_search`` dictionary in the ``html_theme_options``.
117120

118-
Additional options include:
119-
120-
1. ``keys``: List of keys to search in the documents. Default are ``["title", "text"]``.
121-
2. ``threshold``: The minimum score a search result must have to be included in the results. Default is ``0.5``.
122-
3. ``ignoreLocation``: Whether to ignore the location of the search term in the document. Default is ``False``. Ignoring the location can increase the search speed for large documents.
123-
4. ``limit``: The maximum number of search results to display. Default is ``10``.
124-
5. ``min_chars_for_search``: The minimum number of characters required to start the search. Default is ``1``.
121+
To improve the search performance, a debounce function is available. By
122+
default, a delay of 300 milliseconds is applied. To modify this value, declare
123+
the ``delay`` key in the ``static_search`` dictionary with a value specifying
124+
the amount of milliseconds to wait before executing the search. A value of
125+
``0`` disables the debounce function.
125126

126127
.. note::
127128

128129
All other options are available in the `Fuse.js documentation <https://fusejs.io/api/options.html>`_.
129130

130-
Here is an example of how to add the ``static_search`` dictionary to the ``html_theme_options`` dictionary:
131+
Here is an example of how to add the ``static_search`` dictionary to the
132+
``html_theme_options`` dictionary:
131133

132134
.. code-block:: python
133135
134136
html_theme_options = {
135137
"static_search": {
136138
"threshold": 0.5,
137139
"limit": 10,
138-
"min_chars_for_search": 1,
140+
"minMatchCharLength": 1,
141+
"delay": 300,
139142
},
140143
}
141144
142145
143146
.. note::
144147

145-
Serve locally your documentation using the ``python -m http.server -d /path/to/docs/html/`` to have a live-preview of your search results. This method is compliant with the `CORS policy <https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS>`_ and allows to load the generated resource files containing the indices of your documentation.
146-
The search bar does not work if you open the HTML files directly in the browser.
148+
Serve locally your documentation using the ``python -m http.server -d
149+
/path/to/docs/html/`` to have a live-preview of your search results. This
150+
method is compliant with the `CORS policy
151+
<https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS>`_ and allows to
152+
load the generated resource files containing the indices of your
153+
documentation. The search bar does not work if you open the HTML files
154+
directly in the browser.
147155

148-
To open the documentation in a local server, run the following command in the directory where the HTML files are located:
156+
To open the documentation in a local server, run the following command in
157+
the directory where the HTML files are located:
149158

150159
.. code-block:: bash
151160

doc/styles/config/vocabularies/ANSYS/accept.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(?i)theme
44
(?i)Boolean
55
datatable
6+
debounce
67
MeiliSearch
78
(?i)linkcode
89
link_code_library
@@ -21,4 +22,4 @@ Gedam
2122
Chris
2223
Sewell
2324
(?i)Sphinx-Gallery
24-
(?i)favicon
25+
(?i)favicon

src/ansys_sphinx_theme/search/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ def update_search_config(app: Sphinx) -> None:
3737
theme_static_options = app.config.html_theme_options.get("static_search", {})
3838
theme_static_options["keys"] = ["title", "text"]
3939
theme_static_options["threshold"] = theme_static_options.get("threshold", 0.5)
40-
theme_static_options["shouldSort"] = theme_static_options.get("shouldSort", "True")
41-
theme_static_options["ignoreLocation"] = theme_static_options.get("ignoreLocation", "False")
42-
theme_static_options["useExtendedSearch"] = theme_static_options.get(
43-
"useExtendedSearch", "True"
44-
)
4540
theme_static_options["limit"] = theme_static_options.get("limit", 10)
46-
theme_static_options["min_chars_for_search"] = theme_static_options.get(
47-
"min_chars_for_search", 1
48-
)
41+
42+
43+
__all__ = ["create_search_index", "update_search_config"]

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/components/ast-search-button.html

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,13 @@
22
<link rel="stylesheet" href="{{ pathto('_static/css/fuse-search.css', 1) }}">
33

44

5-
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
6-
7-
{% if theme_static_search %}
8-
9-
{% set theme_static_search = theme_static_search | default({}) %}
10-
{% else %}
11-
{% set theme_static_search = {'keys': ['title', 'text'], 'threshold': 0.5, 'shouldSort': 'True', 'ignoreLocation': 'False', 'useExtendedSearch': 'True'} %}
12-
{% endif %}
13-
14-
{% set theme_limit = theme_static_search.limit | default(10) %}
15-
{% set min_chars_for_search = theme_static_search.min_chars_for_search | default(1) %}
5+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.7/require.min.js"></script>
166

177
<script>
18-
var theme_static_search = JSON.parse('{{ theme_static_search | tojson | safe }}');
19-
var theme_limit = "{{ theme_limit }}";
20-
var min_chars_for_search = "{{ min_chars_for_search }}";
21-
var searchPath = "{{ pathto('_static/search.json', 1) }}";
22-
8+
// Passing the search options to the search.js file
9+
const SEARCH_OPTIONS = JSON.parse('{{ theme_static_search | tojson | safe }}');
10+
const SEARCH_FILE = "{{ pathto('_static/search.json', 1) }}";
2311
</script>
2412

25-
<script src="{{ pathto('_static/js/fuse_search.js', 1) }}"></script>
26-
<script src="{{ pathto('_static/js/fuse_extension.js', 1) }}"></script>
13+
14+
<script src="{{ pathto('_static/js/search.js', 1) }}"></script>
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22
<div class="search-bar" id="search-bar">
3-
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
4-
<i class="fa-solid fa-magnifying-glass"></i>
5-
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
6-
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
7-
autocapitalize="off" spellcheck="false"/>
8-
<span class="search-button__kbd-shortcut">
9-
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
10-
</span>
11-
</form>
12-
<!-- Search results container -->
13-
<div id="results" class="results" style="display: none;" tabindex="0">
14-
</div>
3+
<form class="bd-search d-flex align-items-center" action="{{ pathto('search') }}" method="get">
4+
<i class="fa-solid fa-magnifying-glass"></i>
5+
<input type="search" class="form-control" name="q" placeholder="{{ theme_search_bar_text }}"
6+
aria-label="{{ theme_search_bar_text }}" autocomplete="off" autocorrect="off"
7+
autocapitalize="off" spellcheck="false"/>
8+
<span class="search-button__kbd-shortcut">
9+
<kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd>
10+
</span>
11+
</form>
12+
<div id="search-results" class="search-results" style="display: none;" tabindex="0"></div>
13+
</div>

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/ansys_sphinx_theme.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@import "ansys-sphinx-theme-variables.css";
66
@import "pydata-sphinx-theme-custom.css";
77
@import "breadcrumbs.css";
8-
@import "fuse-search.css";
8+
@import "ast-search.css";
99
@import "sphinx-design.css";
1010
@import "table-custom.css";
1111
@import "sphinx-gallery.css";

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/fuse-search.css renamed to src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/css/ast-search.css

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,48 @@
11
@import "ansys-sphinx-theme-variable.css";
22

3-
.results {
3+
.search-results {
44
display: flex;
55
flex-direction: column;
6-
align-content: flex-start;
7-
justify-content: center;
6+
align-content: stretch;
7+
justify-content: flex-start;
88
position: absolute;
99
background-color: var(--ast-search-bar-enable-background);
10-
width: 700px;
11-
padding: 10px;
10+
width: 630px;
11+
padding: 1em;
1212
border: 1px solid var(--ast-search-bar-enable-border);
1313
box-shadow: var(--ast-box-shadow-active);
1414
overflow: auto;
15-
height: 500px;
16-
}
17-
.search-button__wrapper.show .search-button__search-container {
18-
overflow: auto;
15+
max-height: 500px;
1916
}
17+
2018
.result-item {
21-
margin-bottom: 1rem;
22-
cursor: pointer; /* Indicate that the item is clickable */
23-
transition: box-shadow 0.3s ease; /* Smooth transition */
19+
cursor: pointer;
20+
transition: box-shadow 0.3s ease;
21+
border-bottom: thin solid var(--ast-search-bar-enable-border);
22+
padding-bottom: 0.5em;
23+
margin-bottom: 0.5em;
24+
}
25+
26+
.result-item:last-child {
27+
border-bottom: 0;
28+
margin-bottom: 0;
2429
}
2530

2631
.result-title {
2732
font-size: 1em;
2833
font-weight: bold;
29-
background-color: var(--ast-suggestion-header-background);
3034
font-family: "Open Sans", sans-serif;
3135
color: var(--ast-catagory-header-text);
3236
}
3337

34-
.result-title:focus,
35-
.result-title:focus-visible,
36-
.result-text:focus,
37-
.result-text:focus-visible {
38-
box-shadow: var(--ast-ring-shadow-focused);
39-
}
40-
41-
.result-item.selected {
42-
box-shadow: var(--ast-ring-shadow-focused);
43-
}
44-
4538
.result-text {
4639
font-size: 12px;
4740
font-family: "Open Sans", sans-serif;
4841
color: var(--ast-search-bar-enable-text);
4942
}
5043

51-
.result-item:focus-visible,
52-
.result-item:focus {
53-
outline: none; /* Remove default focus outline */
54-
cursor: pointer;
44+
.result-item.selected {
5545
box-shadow: var(--ast-ring-shadow-focused);
56-
z-index: 1;
57-
}
58-
59-
.result-item:hover {
60-
background-color: var(
61-
--ast-hover-suggestion-text-background
62-
); /* Background when hovered */
63-
}
64-
65-
.no-results {
66-
font-style: italic;
67-
color: var(--ast-color-text);
68-
font-family: "Open Sans", sans-serif;
6946
}
7047

7148
html[data-theme="light"] .highlight {

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/static/js/fuse_extension.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)