Skip to content

Commit 8edf550

Browse files
Revathyvenugopal162pyansys-ci-botSMoraisAnsys
authored
fix: exclude search files (#572)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Sébastien Morais <[email protected]>
1 parent f179e01 commit 8edf550

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: exclude search files

doc/source/user-guide/options.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ the ``delay`` key in the ``static_search`` dictionary with a value specifying
124124
the amount of milliseconds to wait before executing the search. A value of
125125
``0`` disables the debounce function.
126126

127+
Additionally, you can decide the limit of the search results by setting the
128+
``limit`` key in the ``static_search`` dictionary. The default value is ``10``.
129+
130+
To exclude files or directories from the search index, you can use the
131+
``files_to_exclude`` key in the ``static_search`` dictionary. This key is a list
132+
of strings representing the directories or files to exclude from the search
133+
index.
134+
135+
Here is an example of how to add the ``static_search`` dictionary to the
136+
``html_theme_options`` dictionary:
137+
138+
.. code-block:: python
139+
140+
html_theme_options = {
141+
"static_search": {
142+
"threshold": 0.5,
143+
"limit": 10,
144+
"minMatchCharLength": 1,
145+
"delay": 300,
146+
"files_to_exclude": ["_build", "api/", "examples/sphinx_demo"],
147+
},
148+
}
149+
127150
To customise the indexing of your documentation, you can use the ``index_patterns`` dictionary in the ``conf.py`` file.
128151
This dictionary contains the paths to the directories you want to index and the type of nodes to index.
129152
The type of nodes can be ``ALL_NODES``, ``TITLES`` or ``PARAGRAPHS``.

src/ansys_sphinx_theme/search/fuse_search.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,21 @@ def create_search_index(app, exception):
204204

205205
search_index_list = []
206206

207-
for document in app.env.found_docs:
207+
static_search_options = app.config.html_theme_options.get("static_search", {})
208+
excluded_docs = static_search_options.get("files_to_exclude", [])
209+
included_docs = app.env.found_docs
210+
211+
for exclude_doc in excluded_docs:
212+
exclude_doc = Path(exclude_doc).resolve()
213+
214+
# Exclude documents based on whether exclude_doc is a folder or a file:
215+
# - For folders, exclude all documents within the folder.
216+
# - For files, exclude only the exact file match.
217+
included_docs = [
218+
doc for doc in included_docs if not Path(doc).resolve().is_relative_to(exclude_doc)
219+
]
220+
221+
for document in included_docs:
208222
pattern = get_pattern_for_each_page(app, document)
209223
search_index = SearchIndex(document, app, pattern)
210224
search_index.build_sections()

0 commit comments

Comments
 (0)