Skip to content

Commit 24c568d

Browse files
Revathyvenugopal162pyansys-ci-botjorgepiloto
authored
feat: add multi index searching and filtering (#674)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Jorge Martínez <[email protected]>
1 parent e832a5b commit 24c568d

File tree

14 files changed

+866
-114
lines changed

14 files changed

+866
-114
lines changed

doc/changelog.d/674.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add multi index searching and filtering

doc/source/_static/search_filter.png

31.4 KB
Loading

doc/source/conf.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,23 @@
6868
"version_match": get_version_match(__version__),
6969
},
7070
"logo": "ansys",
71-
"static_search": {
72-
"threshold": 0.2,
73-
"limit": 7,
74-
"minMatchCharLength": 3,
71+
"search_extra_sources": {
72+
"PyDPF Core": "https:/dpf.docs.pyansys.com/version/stable/",
73+
"Actions": "https://actions.docs.ansys.com/version/stable/",
74+
},
75+
"search_filters": {
76+
"User Guide": [
77+
"user-guide/",
78+
"getting-started/",
79+
"index/",
80+
],
81+
"Release Notes": ["changelog"],
82+
"Examples": ["examples/"],
83+
"Contributing": ["contribute/"],
7584
},
7685
}
7786

87+
7888
html_js_files = ["https://cdn.plot.ly/plotly-3.0.1.min.js"]
7989

8090

doc/source/user-guide/options.rst

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,6 @@ Here is an example of how to add the ``static_search`` dictionary to the
147147
},
148148
}
149149
150-
To customise the indexing of your documentation, you can use the ``index_patterns`` dictionary in the ``conf.py`` file.
151-
This dictionary contains the paths to the directories you want to index and the type of nodes to index.
152-
The type of nodes can be ``ALL_NODES``, ``TITLES`` or ``PARAGRAPHS``.
153-
The default value is ``TITLES + PARAGRAPHS``.
154-
155-
Here is an example of how to add the ``index_patterns`` dictionary to the `conf.py`` file:
156-
157-
.. code-block:: python
158-
159-
index_patterns = {
160-
"api/": ALL_NODES,
161-
"examples/": TITLES + PARAGRAPHS,
162-
}
163-
164-
The above example indexes all nodes in the ``api/`` directory and only titles and paragraphs in the ``examples/`` directory.
165-
166-
167150
.. note::
168151

169152
All other options are available in the `Fuse.js documentation <https://fusejs.io/api/options.html>`_.
@@ -203,6 +186,63 @@ Here is an example of how to add the ``static_search`` dictionary to the
203186
Then, open the browser and go to ``http://localhost:8000``.
204187

205188

189+
Advanced search options
190+
~~~~~~~~~~~~~~~~~~~~~~~
191+
192+
The Ansys Sphinx theme supports advanced search capabilities to enhance the user experience.
193+
194+
These options can be configured through the ``html_theme_options`` dictionary in your ``conf.py`` file.
195+
196+
Multi-index search
197+
^^^^^^^^^^^^^^^^^^
198+
199+
To enable search across multiple documentation sources, use the ``search_extra_sources`` key.
200+
This key should be assigned a list of dictionaries, where each dictionary represents an external index.
201+
Each entry must contain a display name and the URL of the documentation to be included.
202+
203+
**Example:**
204+
205+
.. code-block:: python
206+
207+
html_theme_options = {
208+
"search_extra_sources": [
209+
{"name": "PyMAPDL", "url": "https://mapdl.docs.pyansys.com/version/stable/"},
210+
{"name": "PyAnsys", "url": "https://docs.pyansys.com/version/stable/"},
211+
],
212+
}
213+
214+
Search filters
215+
^^^^^^^^^^^^^^
216+
217+
To organize and group search results, you can define custom filters using the ``search_filters`` key.
218+
This key should be a dictionary where each key represents a filter label and the corresponding value is a list of directories or file paths that belong to that filter.
219+
220+
**Example:**
221+
222+
.. code-block:: python
223+
224+
html_theme_options = {
225+
"search_filters": {
226+
"User Guide": [
227+
"user-guide/",
228+
"getting-started/",
229+
"index/",
230+
],
231+
"Release Notes": ["changelog"],
232+
"Examples": ["examples/"],
233+
"Contributing": ["contribute/"],
234+
},
235+
}
236+
237+
The filters appears as clickable options in the search interface, allowing users to refine their results by content type.
238+
239+
The search filters are displayed as below:
240+
241+
.. image:: ../_static/search_filter.png
242+
:alt: Search filters
243+
244+
245+
206246
Cheat sheets
207247
------------
208248

src/ansys_sphinx_theme/__init__.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
from ansys_sphinx_theme.extension.linkcode import DOMAIN_KEYS, sphinx_linkcode_resolve
3737
from ansys_sphinx_theme.latex import generate_404
3838
from ansys_sphinx_theme.search import (
39-
ALL_NODES,
40-
PARAGRAPHS,
41-
TITLES,
4239
create_search_index,
4340
update_search_config,
4441
)
@@ -456,6 +453,35 @@ def add_sidebar_context(
456453
context["sidebars"] = sidebar
457454

458455

456+
def update_search_sidebar_context(
457+
app: Sphinx, pagename: str, templatename: str, context: dict, doctree: nodes.document
458+
) -> None:
459+
"""Update the search sidebar context.
460+
461+
This function updates the search sidebar context with the search index
462+
and the search options.
463+
464+
Parameters
465+
----------
466+
app : sphinx.application.Sphinx
467+
Application instance for rendering the documentation.
468+
pagename : str
469+
Name of the current page.
470+
templatename : str
471+
Name of the template being used.
472+
context : dict
473+
Context dictionary for the page.
474+
doctree : docutils.nodes.document
475+
Document tree for the page.
476+
"""
477+
sidebar = context.get("sidebars", [])
478+
if pagename == "search" and "search_sidebar.html" not in sidebar:
479+
sidebar.append("search_sidebar.html")
480+
481+
# Update the sidebar context
482+
context["sidebars"] = sidebar
483+
484+
459485
def append_og_site_name(app, pagename, templatename, context, doctree):
460486
# Make sure the context already has metatags
461487
context["metatags"] = context.get("metatags", "")
@@ -511,6 +537,8 @@ def setup(app: Sphinx) -> Dict:
511537
app.connect("html-page-context", update_footer_theme)
512538
app.connect("html-page-context", fix_edit_html_page_context)
513539
app.connect("html-page-context", append_og_site_name)
540+
app.connect("html-page-context", update_search_sidebar_context)
541+
514542
app.connect("build-finished", replace_html_tag)
515543
if use_ansys_search:
516544
app.connect("build-finished", create_search_index)
@@ -521,4 +549,8 @@ def setup(app: Sphinx) -> Dict:
521549
}
522550

523551

524-
__all__ = ["__version__", "generate_404", "get_version_match", "TITLES", "PARAGRAPHS", "ALL_NODES"]
552+
__all__ = [
553+
"__version__",
554+
"generate_404",
555+
"get_version_match",
556+
]

src/ansys_sphinx_theme/assets/styles/ast-search.scss

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535
/* Result Title */
3636
.result-title {
3737
font-size: 1em;
38-
font-weight: var(--ast-font-weight-bold);
3938
font-family: "Open Sans", sans-serif;
40-
color: var(--ast-catagory-header-text);
39+
color: var(--ast-color-link);
4140
}
4241

4342
/* Result Text */
@@ -49,8 +48,8 @@
4948

5049
/* Highlighted Text */
5150
html[data-theme="light"] .highlight {
52-
color: var(--ast-highlight-color);
53-
font-family: var(--ast-code-family);
51+
color: var(--pst-color-text-base);
52+
font-weight: var(--ast-font-weight-bold);
5453
}
5554

5655
/* Search Input Styles */
@@ -166,4 +165,124 @@ html[data-theme="light"] .highlight {
166165
.bd-search .search-button__kbd-shortcut {
167166
display: none;
168167
}
168+
}
169+
170+
171+
/* ========== General Styles ========== */
172+
173+
.result-item {
174+
padding: 8px;
175+
margin-bottom: 4px;
176+
cursor: pointer;
177+
}
178+
179+
.dropdown-menu.show {
180+
display: block;
181+
}
182+
183+
.dropdown-item {
184+
padding: 10px;
185+
cursor: pointer;
186+
}
187+
188+
/* ========== Search Input ========== */
189+
190+
#search-input {
191+
width: 100%;
192+
max-width: 600px; /* Adjust as needed */
193+
padding: 10px;
194+
margin-bottom: 10px;
195+
}
196+
197+
/* ========== Checkbox Filter Items ========== */
198+
199+
.checkbox-item {
200+
display: flex;
201+
align-items: center;
202+
margin: 0.3125rem 0.625rem; // 5px 10px
203+
}
204+
205+
206+
207+
/* ========== Chips (Selected Filter Tags) ========== */
208+
209+
.chip {
210+
display: inline-flex;
211+
align-items: center;
212+
background-color: var(--ast-hover-suggestion-text-background);
213+
border-radius: 1rem; // 16px
214+
padding: 0.3125rem 0.625rem; // 5px 10px
215+
margin: 0.3125rem; // 5px
216+
}
217+
218+
.chip .remove-btn {
219+
margin-left: 0.5rem; // 8px
220+
background: none;
221+
border: none;
222+
color:var(--ast-search-bar-enable-text);
223+
cursor: pointer;
224+
font-weight: bold;
225+
}
226+
227+
.chip .remove-btn:hover {
228+
color: var(--ast-search-bar-enable-background);
229+
}
230+
231+
/* Dropdown items inside chips if needed */
232+
.chip .dropdown-item {
233+
padding: 0.3125rem 0.625rem; // 5px 10px
234+
cursor: pointer;
235+
}
236+
237+
/* ========== Dropdown Panels (Sidebar) ========== */
238+
239+
#objectid-dropdown,
240+
#library-dropdown {
241+
position: relative;
242+
top: 100%; /* Directly below parent */
243+
left: 0.625rem; // 10px
244+
background-color: transparent;
245+
border: none;
246+
display: block;
247+
}
248+
249+
.search-page-sidebar.toggle-section {
250+
display: flex;
251+
align-items: center;
252+
cursor: pointer;
253+
padding: 0.3125rem 0.625rem; // 5px 10px
254+
border-radius: 0.3125rem; // 5px
255+
margin-top: 0.3125rem; // 5px
256+
}
257+
258+
.search-page-sidebar.toggle-section.active {
259+
background-color: var(--ast-hover-suggestion-text-background);
260+
font-weight: bold;
261+
}
262+
263+
.toggle-icon {
264+
padding: 0.5rem; // 8px
265+
}
266+
267+
.checkmark {
268+
margin-right: 0.3125rem; // 5px
269+
color: var(--ast-search-bar-enable-text);
270+
font-weight: 400;
271+
}
272+
273+
.result-limit-wrapper {
274+
display: flex;
275+
align-items: center;
276+
margin: 0 0.625rem; // 0 10px
277+
font-size: 0.875rem; /* 14px */
278+
color: var(--ast-search-bar-enable-text);
279+
}
280+
281+
select {
282+
background-color: var(--ast-search-bar-enable-background);
283+
color: var(--ast-search-bar-enable-text);
284+
border: 0.03125rem solid var(--ast-search-bar-enable-border); /* 0.5px */
285+
border-radius: 0.25rem; /* 4px */
286+
padding: 0.5rem;
287+
font-size: 0.875rem; /* 14px */
169288
}

src/ansys_sphinx_theme/search/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
from sphinx.application import Sphinx
2525

2626
from ansys_sphinx_theme.search.fuse_search import (
27-
ALL_NODES,
28-
LITERAL,
29-
PARAGRAPHS,
30-
TITLES,
3127
create_search_index,
3228
)
3329

@@ -41,7 +37,7 @@ def update_search_config(app: Sphinx) -> None:
4137
Sphinx application.
4238
"""
4339
theme_static_options = app.config.html_theme_options.get("static_search", {})
44-
theme_static_options["keys"] = ["title", "text"]
40+
theme_static_options["keys"] = ["title", "text", "objectID"]
4541
theme_static_options["threshold"] = theme_static_options.get("threshold", 0.2)
4642
theme_static_options["limit"] = theme_static_options.get("limit", 10)
4743
app.add_config_value("index_patterns", {}, "html")
@@ -51,8 +47,4 @@ def update_search_config(app: Sphinx) -> None:
5147
__all__ = [
5248
"create_search_index",
5349
"update_search_config",
54-
"LITERAL",
55-
"PARAGRAPHS",
56-
"TITLES",
57-
"ALL_NODES",
5850
]

0 commit comments

Comments
 (0)