Skip to content

Commit

Permalink
fix: exclude search files (#572)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent f179e01 commit 8edf550
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changelog.d/572.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: exclude search files
23 changes: 23 additions & 0 deletions doc/source/user-guide/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ the ``delay`` key in the ``static_search`` dictionary with a value specifying
the amount of milliseconds to wait before executing the search. A value of
``0`` disables the debounce function.

Additionally, you can decide the limit of the search results by setting the
``limit`` key in the ``static_search`` dictionary. The default value is ``10``.

To exclude files or directories from the search index, you can use the
``files_to_exclude`` key in the ``static_search`` dictionary. This key is a list
of strings representing the directories or files to exclude from the search
index.

Here is an example of how to add the ``static_search`` dictionary to the
``html_theme_options`` dictionary:

.. code-block:: python
html_theme_options = {
"static_search": {
"threshold": 0.5,
"limit": 10,
"minMatchCharLength": 1,
"delay": 300,
"files_to_exclude": ["_build", "api/", "examples/sphinx_demo"],
},
}
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``.
Expand Down
16 changes: 15 additions & 1 deletion src/ansys_sphinx_theme/search/fuse_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,21 @@ def create_search_index(app, exception):

search_index_list = []

for document in app.env.found_docs:
static_search_options = app.config.html_theme_options.get("static_search", {})
excluded_docs = static_search_options.get("files_to_exclude", [])
included_docs = app.env.found_docs

for exclude_doc in excluded_docs:
exclude_doc = Path(exclude_doc).resolve()

# Exclude documents based on whether exclude_doc is a folder or a file:
# - For folders, exclude all documents within the folder.
# - For files, exclude only the exact file match.
included_docs = [
doc for doc in included_docs if not Path(doc).resolve().is_relative_to(exclude_doc)
]

for document in included_docs:
pattern = get_pattern_for_each_page(app, document)
search_index = SearchIndex(document, app, pattern)
search_index.build_sections()
Expand Down

0 comments on commit 8edf550

Please sign in to comment.