From 01f45a12c70320cb9a42c133d340210601103a93 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 23 Sep 2011 10:38:18 +0200 Subject: [PATCH] Fix #727: Fix the links to search results with custom object types. --- CHANGES | 2 ++ sphinx/search.py | 22 ++++++++++++++-------- sphinx/themes/basic/static/searchtools.js | 11 +++++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 690354a67..a8904b31d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Release 1.0.8 (Sep 23, 2011) ============================ +* #727: Fix the links to search results with custom object types. + * #648: Fix line numbers reported in warnings about undefined references. diff --git a/sphinx/search.py b/sphinx/search.py index 51f997c2d..373c80e37 100644 --- a/sphinx/search.py +++ b/sphinx/search.py @@ -121,7 +121,7 @@ class IndexBuilder(object): self._mapping = {} # objtype -> index self._objtypes = {} - # objtype index -> objname (localized) + # objtype index -> (domain, type, objname (localized)) self._objnames = {} def load(self, stream, format): @@ -160,21 +160,27 @@ class IndexBuilder(object): continue if prio < 0: continue - # XXX splitting at dot is kind of Python specific prefix, name = rpartition(fullname, '.') pdict = rv.setdefault(prefix, {}) try: - i = otypes[domainname, type] + typeindex = otypes[domainname, type] except KeyError: - i = len(otypes) - otypes[domainname, type] = i + typeindex = len(otypes) + otypes[domainname, type] = typeindex otype = domain.object_types.get(type) if otype: # use unicode() to fire translation proxies - onames[i] = unicode(domain.get_type_name(otype)) + onames[typeindex] = (domainname, type, + unicode(domain.get_type_name(otype))) else: - onames[i] = type - pdict[name] = (fn2index[docname], i, prio) + onames[typeindex] = (domainname, type, type) + if anchor == fullname: + shortanchor = '' + elif anchor == type + '-' + fullname: + shortanchor = '-' + else: + shortanchor = anchor + pdict[name] = (fn2index[docname], typeindex, prio, shortanchor) return rv def get_terms(self, fn2index): diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 9308c6d5c..04ce07534 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -363,10 +363,13 @@ var Search = { var fullname = (prefix ? prefix + '.' : '') + name; if (fullname.toLowerCase().indexOf(object) > -1) { match = objects[prefix][name]; - descr = objnames[match[1]] + _(', in ') + titles[match[0]]; - // XXX the generated anchors are not generally correct - // XXX there may be custom prefixes - result = [filenames[match[0]], fullname, '#'+fullname, descr]; + descr = objnames[match[1]][0] + _(', in ') + titles[match[0]]; + anchor = match[3]; + if (anchor == '') + anchor = fullname; + else if (anchor == '-') + anchor = objnames[match[1]][1] + '-' + fullname; + result = [filenames[match[0]], fullname, '#'+anchor, descr]; switch (match[2]) { case 1: objectResults.push(result); break; case 0: importantResults.push(result); break;