Skip to content

Commit

Permalink
HTML search: Add test coverage & introduce test module file suffix (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison authored Aug 11, 2024
1 parent 918feed commit 3bab324
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/js/fixtures/partial/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/titles/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/js/jasmine-browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export default {
],
specDir: "tests/js",
specFiles: [
'searchtools.js',
'sphinx_highlight.js'
'**/*.spec.js',
],
helpers: [],
env: {
Expand Down
2 changes: 1 addition & 1 deletion tests/js/roots/partial/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sphinx_utils module
===================

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

Expand Down
14 changes: 14 additions & 0 deletions tests/js/roots/titles/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ the subject area they're researching.

.. automodule:: relevance
:members:

Result Scoring
--------------

Many search engines assign a numeric score to documents during retrieval of
results - and this score is often used to determine the order in which they
will be presented to the user.

For example, if a user issues a query for a two words, then documents that
contain both of the words would typically be scored more highly than documents
which only contain one of them.

By evaluating search results and collecting user feedback over time, we can
attempt to align document :index:`!scoring` with :index:`relevance`.
46 changes: 46 additions & 0 deletions tests/js/searchtools.js → tests/js/searchtools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ describe('Basic html theme search', function() {
expect(Search.performTermsSearch(searchterms, excluded)).toEqual(hits);
});

it('should partially-match within "possible" when in term index', function() {
eval(loadFixture("partial/searchindex.js"));

[_searchQuery, searchterms, excluded, ..._remainingItems] = Search._parseQuery('ossibl');
terms = Search._index.terms;
titleterms = Search._index.titleterms;

hits = [[
"index",
"sphinx_utils module",
"",
null,
2,
"index.rst"
]];
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
});

});

describe('aggregation of search results', function() {
Expand Down Expand Up @@ -141,6 +159,34 @@ describe('Basic html theme search', function() {
checkRanking(expectedRanking, results);
});

it('should score a title match above a standard index entry match', function() {
eval(loadFixture("titles/searchindex.js"));

expectedRanking = [
['relevance', 'Relevance', ''], /* title */
['index', 'Main Page', '#index-1'], /* index entry */
];

searchParameters = Search._parseQuery('relevance');
results = Search._performSearch(...searchParameters);

checkRanking(expectedRanking, results);
});

it('should score a priority index entry match above a title match', function() {
eval(loadFixture("titles/searchindex.js"));

expectedRanking = [
['index', 'Main Page', '#index-0'], /* index entry */
['index', 'Main Page > Result Scoring', '#result-scoring'], /* title */
];

searchParameters = Search._parseQuery('scoring');
results = Search._performSearch(...searchParameters);

checkRanking(expectedRanking, results);
});

it('should score a main-title match above a subheading-title match', function() {
eval(loadFixture("titles/searchindex.js"));

Expand Down
File renamed without changes.

0 comments on commit 3bab324

Please sign in to comment.