diff options
author | Jakob Lykke Andersen <Jakob@caput.dk> | 2021-09-18 15:28:18 +0200 |
---|---|---|
committer | Jakob Lykke Andersen <Jakob@caput.dk> | 2021-09-25 10:59:49 +0200 |
commit | b6e60d4993a1912df9ab869f52be9e60fb97da87 (patch) | |
tree | 0f78b9c57661ad0f14a0c3bd8127d70a3a0db041 | |
parent | 356583fe8fe6f6b6662898c8367f9bc9c1da387b (diff) | |
download | sphinx-git-b6e60d4993a1912df9ab869f52be9e60fb97da87.tar.gz |
search, store objects as array to retain all
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | sphinx/search/__init__.py | 4 | ||||
-rw-r--r-- | sphinx/themes/basic/static/searchtools.js | 5 | ||||
-rw-r--r-- | tests/test_search.py | 9 |
4 files changed, 14 insertions, 6 deletions
@@ -24,6 +24,8 @@ Bugs fixed * #9630: autosummary: Failed to build summary table if :confval:`primary_domain` is not 'py' * #9670: html: Fix download file with special characters +* HTML search: when objects have the same name but in different domains, + return all of them as result instead of just one. Testing -------- diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index ecdf880d7..d3059b6da 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -318,7 +318,7 @@ class IndexBuilder: 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: @@ -337,7 +337,7 @@ class IndexBuilder: 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]]]: diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 58ff35c43..002e9c4a2 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -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) { @@ -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 diff --git a/tests/test_search.py b/tests/test_search.py index 7b9d5c40b..18407875f 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -66,7 +66,11 @@ test that non-comments are indexed: fermion def test_objects_are_escaped(app, status, warning): app.builder.build_all() index = jsload(app.outdir / 'searchindex.js') - assert 'n::Array<T, d>' in index.get('objects').get('') # n::Array<T,d> is escaped + for item in index.get('objects').get(''): + if item[-1] == 'n::Array<T, d>': # n::Array<T,d> is escaped + break + else: + assert False, index.get('objects').get('') @pytest.mark.sphinx(testroot='search') @@ -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], |