mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
[search] fix multiple term matching edge case (#11960)
This commit is contained in:
parent
1e4f80d7a4
commit
ae51974e21
@ -33,6 +33,8 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #11959: Fix multiple term matching when word appears in both title and document.
|
||||||
|
Patch by Will Lachance.
|
||||||
* #11958: HTML Search: Fix partial matches overwriting full matches.
|
* #11958: HTML Search: Fix partial matches overwriting full matches.
|
||||||
Patch by William Lachance.
|
Patch by William Lachance.
|
||||||
* #11944: Use anchor in search preview.
|
* #11944: Use anchor in search preview.
|
||||||
|
@ -511,9 +511,8 @@ const Search = {
|
|||||||
|
|
||||||
// create the mapping
|
// create the mapping
|
||||||
files.forEach((file) => {
|
files.forEach((file) => {
|
||||||
if (fileMap.has(file) && fileMap.get(file).indexOf(word) === -1)
|
if (!fileMap.has(file)) fileMap.set(file, [word]);
|
||||||
fileMap.get(file).push(word);
|
else if (fileMap.get(file).indexOf(word) === -1) fileMap.get(file).push(word);
|
||||||
else fileMap.set(file, [word]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -27,6 +27,33 @@ describe('Basic html theme search', function() {
|
|||||||
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to search for multiple terms', function() {
|
||||||
|
index = {
|
||||||
|
alltitles: {
|
||||||
|
'Main Page': [[0, 'main-page']],
|
||||||
|
},
|
||||||
|
docnames:["index"],
|
||||||
|
filenames:["index.rst"],
|
||||||
|
terms:{main:0, page:0},
|
||||||
|
titles:["Main Page"],
|
||||||
|
titleterms:{ main:0, page:0 }
|
||||||
|
}
|
||||||
|
Search.setIndex(index);
|
||||||
|
|
||||||
|
searchterms = ['main', 'page'];
|
||||||
|
excluded = [];
|
||||||
|
terms = index.terms;
|
||||||
|
titleterms = index.titleterms;
|
||||||
|
hits = [[
|
||||||
|
'index',
|
||||||
|
'Main Page',
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
15,
|
||||||
|
'index.rst']];
|
||||||
|
expect(Search.performTermsSearch(searchterms, excluded, terms, titleterms)).toEqual(hits);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user