Skip to content

Commit

Permalink
search, store objects as array to retain all
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobandersen committed Sep 18, 2021
1 parent a900600 commit 9aa5ed9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -23,6 +23,8 @@ Bugs fixed
* #9644: autodoc: Crashed on getting source info from problematic object
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
is not 'py'
* HTML search: when objects have the same name but in different domains,
return all of them as result instead of just one.

Testing
--------
Expand Down
4 changes: 2 additions & 2 deletions sphinx/search/__init__.py
Expand Up @@ -318,7 +318,7 @@ def get_objects(self, fn2index: Dict[str, int]
fullname = html.escape(fullname)
dispname = html.escape(dispname)
prefix, _, name = dispname.rpartition('.')
pdict = rv.setdefault(prefix, {})
plist = rv.setdefault(prefix, [])
try:
typeindex = otypes[domainname, type]
except KeyError:
Expand All @@ -337,7 +337,7 @@ def get_objects(self, fn2index: Dict[str, int]
shortanchor = '-'
else:
shortanchor = anchor
pdict[name] = (fn2index[docname], typeindex, prio, shortanchor)
plist.append((fn2index[docname], typeindex, prio, shortanchor, name))
return rv

def get_terms(self, fn2index: Dict) -> Tuple[Dict[str, List[str]], Dict[str, List[str]]]:
Expand Down
5 changes: 3 additions & 2 deletions sphinx/themes/basic/static/searchtools.js
Expand Up @@ -328,7 +328,9 @@ var Search = {
var results = [];

for (var prefix in objects) {
for (var name in objects[prefix]) {
for (var iMatch = 0; iMatch != objects[prefix].length; ++iMatch) {
var match = objects[prefix][iMatch];
var name = match[4];
var fullname = (prefix ? prefix + '.' : '') + name;
var fullnameLower = fullname.toLowerCase()
if (fullnameLower.indexOf(object) > -1) {
Expand All @@ -342,7 +344,6 @@ var Search = {
} else if (parts[parts.length - 1].indexOf(object) > -1) {
score += Scorer.objPartialMatch;
}
var match = objects[prefix][name];
var objname = objnames[match[1]][2];
var title = titles[match[0]];
// If more than one term searched for, we require other words to be
Expand Down
9 changes: 7 additions & 2 deletions tests/test_search.py
Expand Up @@ -66,7 +66,11 @@ def is_registered_term(index, keyword):
def test_objects_are_escaped(app, status, warning):
app.builder.build_all()
index = jsload(app.outdir / 'searchindex.js')
assert 'n::Array&lt;T, d&gt;' in index.get('objects').get('') # n::Array<T,d> is escaped
for item in index.get('objects').get(''):
if item[-1] == 'n::Array&lt;T, d&gt;': # n::Array<T,d> is escaped
break
else:
assert False, index.get('objects').get('')


@pytest.mark.sphinx(testroot='search')
Expand Down Expand Up @@ -165,7 +169,8 @@ def test_IndexBuilder():
'docnames': ('docname1_1', 'docname1_2', 'docname2_1', 'docname2_2'),
'envversion': '1.0',
'filenames': ['filename1_1', 'filename1_2', 'filename2_1', 'filename2_2'],
'objects': {'': {'objdispname1': (2, 1, 1, '#anchor')}},
'objects': {'': [(0, 0, 1, '#anchor', 'objdispname1'),
(2, 1, 1, '#anchor', 'objdispname1')]},
'objnames': {0: ('dummy1', 'objtype1', 'objtype1'), 1: ('dummy2', 'objtype1', 'objtype1')},
'objtypes': {0: 'dummy1:objtype1', 1: 'dummy2:objtype1'},
'terms': {'ar': [0, 1, 2, 3],
Expand Down

0 comments on commit 9aa5ed9

Please sign in to comment.