Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const _finishSearch = (resultCount) => {
`Search finished, found ${resultCount} page(s) matching the search query.`
);
};
const _displayNextItem = (
let _displayNextItem = (
results,
resultCount,
searchTerms
Expand Down Expand Up @@ -288,7 +288,7 @@ const Search = {
results.push([
docNames[file],
titles[file] !== title ? `${titles[file]} > ${title}` : title,
id !== null ? "#" + id : "",
titles[file] !== title && id !== null ? "#" + id : "",
null,
score,
filenames[file],
Expand Down Expand Up @@ -488,9 +488,11 @@ const Search = {

// create the mapping
files.forEach((file) => {
if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1)
fileMap.get(file).push(word);
else fileMap.set(file, [word]);
if (!fileMap.has(file)) {
fileMap.set(file, [word]);
} else if (fileMap.get(file).indexOf(word) === -1) {
fileMap.get(file).push(word);
}
});
});

Expand Down
8 changes: 8 additions & 0 deletions tests/js/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
const DOCUMENTATION_OPTIONS = {};

// stub Stemmer / stopWords
function Stemmer() {
this.stemWord = function (word) {
return word;
}
};
let stopwords = [];
30 changes: 30 additions & 0 deletions tests/js/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ describe('Basic html theme search', function() {

});

describe('query', function() {
it("should not duplicate on title and content", function() {
index = {
alltitles: {
'Main Page': [[1, 'main-page']],
},
docnames:["", "index"],
filenames:["", "index.rst"],
indexentries:{},
objects:{},
objtypes: {},
objnames: {},
terms:{main:1, page:1},
titles:["", "Main Page"],
titleterms:{ main:1, page:1 }
}
Search.setIndex(index);

_displayNextItem = jasmine.createSpy();
Search.query('main page');

// should only be one result
expect(_displayNextItem).toHaveBeenCalledWith(
[ [ 'index', 'Main Page', '', null, 100, 'index.rst' ] ],
1,
new Set([ 'main', 'page' ])
);
});
})

});

// This is regression test for https://github.com/sphinx-doc/sphinx/issues/3150
Expand Down