Skip to content

Commit 3bab324

Browse files
authored
HTML search: Add test coverage & introduce test module file suffix (#12759)
1 parent 918feed commit 3bab324

File tree

7 files changed

+64
-5
lines changed

7 files changed

+64
-5
lines changed

tests/js/fixtures/partial/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/js/fixtures/titles/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/js/jasmine-browser.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export default {
1010
],
1111
specDir: "tests/js",
1212
specFiles: [
13-
'searchtools.js',
14-
'sphinx_highlight.js'
13+
'**/*.spec.js',
1514
],
1615
helpers: [],
1716
env: {

tests/js/roots/partial/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sphinx_utils module
22
===================
33

4-
Partial (also known as "prefix") matches on document titles should be possible
4+
Partial matches on document titles and document terms should both be possible
55
using the JavaScript search functionality included when HTML documentation
66
projects are built.
77

tests/js/roots/titles/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,17 @@ the subject area they're researching.
1818

1919
.. automodule:: relevance
2020
:members:
21+
22+
Result Scoring
23+
--------------
24+
25+
Many search engines assign a numeric score to documents during retrieval of
26+
results - and this score is often used to determine the order in which they
27+
will be presented to the user.
28+
29+
For example, if a user issues a query for a two words, then documents that
30+
contain both of the words would typically be scored more highly than documents
31+
which only contain one of them.
32+
33+
By evaluating search results and collecting user feedback over time, we can
34+
attempt to align document :index:`!scoring` with :index:`relevance`.

tests/js/searchtools.js renamed to tests/js/searchtools.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ describe('Basic html theme search', function() {
7373
expect(Search.performTermsSearch(searchterms, excluded)).toEqual(hits);
7474
});
7575

76+
it('should partially-match within "possible" when in term index', function() {
77+
eval(loadFixture("partial/searchindex.js"));
78+
79+
[_searchQuery, searchterms, excluded, ..._remainingItems] = Search._parseQuery('ossibl');
80+
terms = Search._index.terms;
81+
titleterms = Search._index.titleterms;
82+
83+
hits = [[
84+
"index",
85+
"sphinx_utils module",
86+
"",
87+
null,
88+
2,
89+
"index.rst"
90+
]];
91+
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
92+
});
93+
7694
});
7795

7896
describe('aggregation of search results', function() {
@@ -141,6 +159,34 @@ describe('Basic html theme search', function() {
141159
checkRanking(expectedRanking, results);
142160
});
143161

162+
it('should score a title match above a standard index entry match', function() {
163+
eval(loadFixture("titles/searchindex.js"));
164+
165+
expectedRanking = [
166+
['relevance', 'Relevance', ''], /* title */
167+
['index', 'Main Page', '#index-1'], /* index entry */
168+
];
169+
170+
searchParameters = Search._parseQuery('relevance');
171+
results = Search._performSearch(...searchParameters);
172+
173+
checkRanking(expectedRanking, results);
174+
});
175+
176+
it('should score a priority index entry match above a title match', function() {
177+
eval(loadFixture("titles/searchindex.js"));
178+
179+
expectedRanking = [
180+
['index', 'Main Page', '#index-0'], /* index entry */
181+
['index', 'Main Page > Result Scoring', '#result-scoring'], /* title */
182+
];
183+
184+
searchParameters = Search._parseQuery('scoring');
185+
results = Search._performSearch(...searchParameters);
186+
187+
checkRanking(expectedRanking, results);
188+
});
189+
144190
it('should score a main-title match above a subheading-title match', function() {
145191
eval(loadFixture("titles/searchindex.js"));
146192

File renamed without changes.

0 commit comments

Comments
 (0)