Skip to content

feat: add multi index searching and filtering #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3642aca
feat: add main doc as variable
Revathyvenugopal162 Mar 18, 2025
970a35e
feat: add advanced search filters and page
Revathyvenugopal162 Mar 19, 2025
d8b6a77
fix: update the obj id
Revathyvenugopal162 Mar 20, 2025
0b2dc06
feat: add filter as gui
Revathyvenugopal162 Mar 21, 2025
fc1bb42
feat: populate chip
Revathyvenugopal162 Mar 21, 2025
2127475
fix: update the secondary filter
Revathyvenugopal162 Mar 24, 2025
8012300
Merge branch 'main' into feat/search-weight
Revathyvenugopal162 Apr 17, 2025
1134e18
chore: adding changelog file 674.added.md [dependabot-skip]
pyansys-ci-bot Apr 17, 2025
648dfc2
fix: add backup search
Revathyvenugopal162 Apr 18, 2025
a0399f9
feat: update the search button
Revathyvenugopal162 Apr 18, 2025
aad3c0f
feat: add docstrings
Revathyvenugopal162 Apr 18, 2025
ceda35e
feat: add libaries
Revathyvenugopal162 Apr 25, 2025
115cde5
feat: add library
Revathyvenugopal162 Apr 28, 2025
908e1bf
feat: add lib source
Revathyvenugopal162 Apr 28, 2025
49ba625
feat: add both dropdown
Revathyvenugopal162 Apr 29, 2025
57ac38d
feat: add dropdown style
Revathyvenugopal162 Apr 29, 2025
4d6d55a
feat: update the search
Revathyvenugopal162 Apr 29, 2025
d1d8eaa
feat: add conf theme options
Revathyvenugopal162 May 7, 2025
138d180
Merge branch 'main' into feat/search-weight
Revathyvenugopal162 May 7, 2025
6d228f3
Merge branch 'main' into feat/search-weight
Revathyvenugopal162 May 13, 2025
fb3700d
Merge branch 'main' into feat/search-weight
Revathyvenugopal162 May 13, 2025
2178eda
test: update the searchbar
Revathyvenugopal162 May 15, 2025
dbd38de
test: update the search html
Revathyvenugopal162 May 15, 2025
b25a1da
test: update the sidebars
Revathyvenugopal162 May 15, 2025
e095c02
test: update the sidebars
Revathyvenugopal162 May 15, 2025
362411a
Merge branch 'main' into feat/search-weight
Revathyvenugopal162 May 16, 2025
5f8ad5d
feat: highlight text
Revathyvenugopal162 May 16, 2025
f923230
fix: docs ids
Revathyvenugopal162 May 16, 2025
6ad2a62
feat: add extra source
Revathyvenugopal162 May 16, 2025
405bfb7
feat: add extra source link
Revathyvenugopal162 May 16, 2025
067f971
feat: update filters
Revathyvenugopal162 May 16, 2025
3510872
test: nodes
Revathyvenugopal162 May 19, 2025
b1b57b2
fix: remove the filters
Revathyvenugopal162 May 19, 2025
832492b
fix: cleanup the nodes
Revathyvenugopal162 May 20, 2025
fcf1fd8
fix
Revathyvenugopal162 May 20, 2025
2e2e1bb
fix: indexing db
Revathyvenugopal162 May 21, 2025
e32c8e3
feat: update the search js
Revathyvenugopal162 May 21, 2025
a41ce3c
feat: update the search-main limit button
Revathyvenugopal162 May 21, 2025
03720d9
feat: update the search fetch
Revathyvenugopal162 May 21, 2025
fadf516
feat: add the quary parameters
Revathyvenugopal162 May 22, 2025
b84cde7
feat: add the quary to input
Revathyvenugopal162 May 22, 2025
0c8cd6f
feat: add the search query
Revathyvenugopal162 May 22, 2025
5459e3d
feat: update the docname
Revathyvenugopal162 May 22, 2025
6b82b95
docs: add document
Revathyvenugopal162 May 22, 2025
e4d6a63
Merge branch 'main' into feat/search-weight
Revathyvenugopal162 May 22, 2025
2636765
Apply suggestions from code review
Revathyvenugopal162 May 22, 2025
9e43b77
feat: update the search options
Revathyvenugopal162 May 22, 2025
ea60d40
chore: adding changelog file 674.added.md [dependabot-skip]
pyansys-ci-bot May 22, 2025
69d91b8
feat: update the section name
Revathyvenugopal162 May 22, 2025
713254f
fix: index
Revathyvenugopal162 May 23, 2025
0c1ee61
fix: add ctrl+enter for advanced page shortcut
Revathyvenugopal162 May 23, 2025
f3ebc03
fix: open the search bar
Revathyvenugopal162 May 23, 2025
8329ffb
fix: searchbar filter
Revathyvenugopal162 May 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/674.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add multi index searching and filtering
Binary file added doc/source/_static/search_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 14 additions & 13 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from sphinx.builders.latex import LaTeXBuilder

from ansys_sphinx_theme import (
ALL_NODES,
PARAGRAPHS,
TITLES,
__version__,
ansys_favicon,
ansys_logo_white,
Expand Down Expand Up @@ -71,20 +68,24 @@
"version_match": get_version_match(__version__),
},
"logo": "ansys",
"static_search": {
"threshold": 0.2,
"limit": 7,
"minMatchCharLength": 3,
"search_extra_sources": {
"PyDPF Core": "https:/dpf.docs.pyansys.com/version/stable/",
"Actions": "https://actions.docs.ansys.com/version/stable/",
},
"search_filters": {
"User Guide": [
"user-guide/",
"getting-started/",
"index/",
],
"Release Notes": ["changelog"],
"Examples": ["examples/"],
"Contributing": ["contribute/"],
},
}

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


index_patterns = {
"examples/api/": ALL_NODES,
"examples/sphinx_examples/": TITLES + PARAGRAPHS,
}
html_js_files = ["https://cdn.plot.ly/plotly-3.0.1.min.js"]


# Sphinx extensions
Expand Down
74 changes: 57 additions & 17 deletions doc/source/user-guide/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,6 @@
},
}

To customise the indexing of your documentation, you can use the ``index_patterns`` dictionary in the ``conf.py`` file.
This dictionary contains the paths to the directories you want to index and the type of nodes to index.
The type of nodes can be ``ALL_NODES``, ``TITLES`` or ``PARAGRAPHS``.
The default value is ``TITLES + PARAGRAPHS``.

Here is an example of how to add the ``index_patterns`` dictionary to the `conf.py`` file:

.. code-block:: python

index_patterns = {
"api/": ALL_NODES,
"examples/": TITLES + PARAGRAPHS,
}

The above example indexes all nodes in the ``api/`` directory and only titles and paragraphs in the ``examples/`` directory.


.. note::

All other options are available in the `Fuse.js documentation <https://fusejs.io/api/options.html>`_.
Expand Down Expand Up @@ -203,6 +186,63 @@
Then, open the browser and go to ``http://localhost:8000``.


Advanced search options
~~~~~~~~~~~~~~~~~~~~~~~

The Ansys Sphinx theme supports advanced search capabilities to enhance the user experience.

These options can be configured through the ``html_theme_options`` dictionary in your ``conf.py`` file.

Multi-index search
^^^^^^^^^^^^^^^^^^

To enable search across multiple documentation sources, use the ``search_extra_sources`` key.
This key should be assigned a list of dictionaries, where each dictionary represents an external index.
Each entry must contain a display name and the URL of the documentation to be included.

**Example:**

.. code-block:: python

html_theme_options = {
"search_extra_sources": [
{"name": "PyMAPDL", "url": "https://mapdl.docs.pyansys.com/version/stable/"},
{"name": "PyAnsys", "url": "https://docs.pyansys.com/version/stable/"},
],
}

Search filters
^^^^^^^^^^^^^^

To organize and group search results, you can define custom filters using the ``search_filters`` key.
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.

**Example:**

.. code-block:: python

html_theme_options = {
"search_filters": {
"User Guide": [
"user-guide/",
"getting-started/",
"index/",
],
"Release Notes": ["changelog"],
"Examples": ["examples/"],
"Contributing": ["contribute/"],
},
}

The filters appears as clickable options in the search interface, allowing users to refine their results by content type.

The search filters are displayed as below:

.. image:: ../_static/search_filter.png
:alt: Search filters



Cheat sheets
------------

Expand Down Expand Up @@ -305,7 +345,7 @@

print("hello world")

If a format is used in the "content" field that does not fall into the categories above, it will not

Check warning on line 348 in doc/source/user-guide/options.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/user-guide/options.rst#L348

[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "doc/source/user-guide/options.rst", "range": {"start": {"line": 348, "column": 93}}}, "severity": "WARNING"}
be rendered correctly.

To enable the "What's new" sections and sidebar in the changelog file, add the following dictionary
Expand All @@ -328,9 +368,9 @@
The dictionary contains the following keys:

- ``whatsnew_file_path``: The path to the YAML file containing what's new content local to the
``doc/source`` directory. If not provided, the what's new section will not be generated.

Check warning on line 371 in doc/source/user-guide/options.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/user-guide/options.rst#L371

[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "doc/source/user-guide/options.rst", "range": {"start": {"line": 371, "column": 69}}}, "severity": "WARNING"}
- ``changelog_file_path``: The path to the changelog.rst file local to the ``doc/source``
directory. If not provided, the what's new section will not be generated.

Check warning on line 373 in doc/source/user-guide/options.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/user-guide/options.rst#L373

[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "doc/source/user-guide/options.rst", "range": {"start": {"line": 373, "column": 54}}}, "severity": "WARNING"}
- ``sidebar_pages``: List of names for the pages to include the what's new sidebar on. If not
provided, the what's new sidebar is not displayed.
- ``sidebar_no_of_headers``: Number of minor version sections to display in the what's new sidebar.
Expand All @@ -355,5 +395,5 @@

.. note::

If you are using both the "whatsnew" and "cheatsheet" options, the "cheatsheet" option will be

Check warning on line 398 in doc/source/user-guide/options.rst

View workflow job for this annotation

GitHub Actions / vale

[vale] doc/source/user-guide/options.rst#L398

[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "doc/source/user-guide/options.rst", "range": {"start": {"line": 398, "column": 92}}}, "severity": "WARNING"}
displayed first in the left navigation pane, followed by the "What's new" section to maintain
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"sass": "^1.85.1"
},
"dependencies": {
"idb": "^8.0.3",
"postcss-scss": "^4.0.9"
}
}
41 changes: 37 additions & 4 deletions src/ansys_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
from ansys_sphinx_theme.extension.linkcode import DOMAIN_KEYS, sphinx_linkcode_resolve
from ansys_sphinx_theme.latex import generate_404
from ansys_sphinx_theme.search import (
ALL_NODES,
PARAGRAPHS,
TITLES,
create_search_index,
update_search_config,
)
Expand Down Expand Up @@ -456,6 +453,36 @@ def add_sidebar_context(
context["sidebars"] = sidebar


def update_search_sidebar_context(
app: Sphinx, pagename: str, templatename: str, context: dict, doctree: nodes.document
) -> None:
"""Update the search sidebar context.

This function updates the search sidebar context with the search index
and the search options.

Parameters
----------
app : sphinx.application.Sphinx
Application instance for rendering the documentation.
pagename : str
Name of the current page.
templatename : str
Name of the template being used.
context : dict
Context dictionary for the page.
doctree : docutils.nodes.document
Document tree for the page.
"""
sidebar = context.get("sidebars", [])
if pagename == "search":
if "search_sidebar.html" not in sidebar:
sidebar.append("search_sidebar.html")

# Update the sidebar context
context["sidebars"] = sidebar


def append_og_site_name(app, pagename, templatename, context, doctree):
# Make sure the context already has metatags
context["metatags"] = context.get("metatags", "")
Expand Down Expand Up @@ -511,6 +538,8 @@ def setup(app: Sphinx) -> Dict:
app.connect("html-page-context", update_footer_theme)
app.connect("html-page-context", fix_edit_html_page_context)
app.connect("html-page-context", append_og_site_name)
app.connect("html-page-context", update_search_sidebar_context)

app.connect("build-finished", replace_html_tag)
if use_ansys_search:
app.connect("build-finished", create_search_index)
Expand All @@ -521,4 +550,8 @@ def setup(app: Sphinx) -> Dict:
}


__all__ = ["__version__", "generate_404", "get_version_match", "TITLES", "PARAGRAPHS", "ALL_NODES"]
__all__ = [
"__version__",
"generate_404",
"get_version_match",
]
133 changes: 129 additions & 4 deletions src/ansys_sphinx_theme/assets/styles/ast-search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
/* Result Title */
.result-title {
font-size: 1em;
font-weight: var(--ast-font-weight-bold);
font-family: "Open Sans", sans-serif;
color: var(--ast-catagory-header-text);
color: var(--ast-color-link);
}

/* Result Text */
Expand All @@ -49,8 +48,8 @@

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

/* Search Input Styles */
Expand Down Expand Up @@ -166,4 +165,130 @@ html[data-theme="light"] .highlight {
.bd-search .search-button__kbd-shortcut {
display: none;
}
}


/* ========== General Styles ========== */

.result-item {
padding: 8px;
margin-bottom: 4px;
cursor: pointer;
}

.dropdown-menu.show {
display: block;
}

.dropdown-item {
padding: 10px;
cursor: pointer;
}

/* ========== Search Input ========== */

#search-input {
width: 100%;
max-width: 600px; /* Adjust as needed */
padding: 10px;
margin-bottom: 10px;
}

/* ========== Checkbox Filter Items ========== */

.checkbox-item {
display: flex;
align-items: center;
margin: 5px 10px;
}



/* ========== Chips (Selected Filter Tags) ========== */

.chip {
display: inline-flex;
align-items: center;
background-color: var(--ast-hover-suggestion-text-background);
border-radius: 16px;
padding: 5px 10px;
margin: 5px;
}

.search-bar-filter{
display: flex;
align-items: center;
gap: 0.5rem;
}

.chip .remove-btn {
margin-left: 8px;
background: none;
border: none;
color:var(--ast-search-bar-enable-text);
cursor: pointer;
font-weight: bold;
}

.chip .remove-btn:hover {
color: var(--ast-search-bar-enable-background);
}

/* Dropdown items inside chips if needed */
.chip .dropdown-item {
padding: 5px 10px;
cursor: pointer;
}

/* ========== Dropdown Panels (Sidebar) ========== */

#objectid-dropdown,
#library-dropdown {
position: relative;
top: 100%; /* Directly below parent */
left: 10px;
background-color: transparent;
border: none;
display: block;
}

.search-page-sidebar.toggle-section {
display: flex;
align-items: center;
cursor: pointer;
padding: 5px 10px;
border-radius: 5px;
margin-top: 5px;
}

.search-page-sidebar.toggle-section.active {
background-color: var(--ast-hover-suggestion-text-background);
font-weight: bold;
}

.toggle-icon {
padding: 8px;
}


.checkmark {
margin-right: 5px;
color: var(--ast-search-bar-enable-text);
font-weight: 400;
}

.result-limit-wrapper {
display: flex;
align-items: center;
margin: 0 10px;
font-size: 0.875rem; /* 14px */
color: var(--ast-search-bar-enable-text);
}
select {
background-color: var(--ast-search-bar-enable-background);
color: var(--ast-search-bar-enable-text);
border: 0.03125rem solid var(--ast-search-bar-enable-border); /* 0.5px */
border-radius: 0.25rem; /* 4px */
padding: 0.5rem;
font-size: 0.875rem; /* 14px */
}
10 changes: 1 addition & 9 deletions src/ansys_sphinx_theme/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
from sphinx.application import Sphinx

from ansys_sphinx_theme.search.fuse_search import (
ALL_NODES,
LITERAL,
PARAGRAPHS,
TITLES,
create_search_index,
)

Expand All @@ -41,7 +37,7 @@ def update_search_config(app: Sphinx) -> None:
Sphinx application.
"""
theme_static_options = app.config.html_theme_options.get("static_search", {})
theme_static_options["keys"] = ["title", "text"]
theme_static_options["keys"] = ["title", "text", "objectID"]
theme_static_options["threshold"] = theme_static_options.get("threshold", 0.2)
theme_static_options["limit"] = theme_static_options.get("limit", 10)
app.add_config_value("index_patterns", {}, "html")
Expand All @@ -51,8 +47,4 @@ def update_search_config(app: Sphinx) -> None:
__all__ = [
"create_search_index",
"update_search_config",
"LITERAL",
"PARAGRAPHS",
"TITLES",
"ALL_NODES",
]
Loading
Loading