Skip to content

Commit fb628cc

Browse files
authored
Convert stopwords to a JavaScript set (#13575)
1 parent 0eae573 commit fb628cc

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

sphinx/themes/basic/static/language_data.js.jinja

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
22
* This script contains the language-specific data used by searchtools.js,
3-
* namely the list of stopwords, stemmer, scorer and splitter.
3+
* namely the set of stopwords, stemmer, scorer and splitter.
44
*/
55

6-
var stopwords = {{ search_language_stop_words }};
6+
const stopwords = new Set({{ search_language_stop_words }});
7+
window.stopwords = stopwords; // Export to global scope
78

89
{% if search_language_stemming_code %}
9-
/* Non-minified version is copied as a separate JS file, if available */
10+
/* Non-minified versions are copied as separate JavaScript files, if available */
1011
{{ search_language_stemming_code|safe }}
1112
{% endif -%}
1213

sphinx/themes/basic/static/searchtools.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,8 @@ const Search = {
287287
const queryTermLower = queryTerm.toLowerCase();
288288

289289
// maybe skip this "word"
290-
// stopwords array is from language_data.js
291-
if (
292-
stopwords.indexOf(queryTermLower) !== -1 ||
293-
queryTerm.match(/^\d+$/)
294-
)
290+
// stopwords set is from language_data.js
291+
if (stopwords.has(queryTermLower) || queryTerm.match(/^\d+$/))
295292
return;
296293

297294
// stem the word

tests/js/language_data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* namely the list of stopwords, stemmer, scorer and splitter.
44
*/
55

6-
var stopwords = [];
6+
const stopwords = new Set([]);
7+
window.stopwords = stopwords; // Export to global scope
78

89

9-
/* Non-minified version is copied as a separate JS file, if available */
10+
/* Non-minified versions are copied as separate JavaScript files, if available */
1011

1112
/**
1213
* Dummy stemmer for languages without stemming rules.

0 commit comments

Comments
 (0)