diff options
author | Luke Plant <L.Plant.98@cantab.net> | 2011-05-14 02:00:44 +0100 |
---|---|---|
committer | Luke Plant <L.Plant.98@cantab.net> | 2011-05-14 02:00:44 +0100 |
commit | 9767e52763ccd3d73af1db6803deba1fa32e08ac (patch) | |
tree | 97ccb1f140e409a492b83d9b159eef80f220adfa | |
parent | d6aa14196f3565c7a0fe5965e513cfc965b4fb97 (diff) | |
download | sphinx-9767e52763ccd3d73af1db6803deba1fa32e08ac.tar.gz |
Pulled object search routine into separate routine.
This makes it easier to re-use, and helps reduce the length of the main query
routine.
-rw-r--r-- | sphinx/themes/basic/static/searchtools.js_t | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/sphinx/themes/basic/static/searchtools.js_t b/sphinx/themes/basic/static/searchtools.js_t index 6be7489f..66d4d84e 100644 --- a/sphinx/themes/basic/static/searchtools.js_t +++ b/sphinx/themes/basic/static/searchtools.js_t @@ -159,9 +159,7 @@ var Search = { var filenames = this._index.filenames; var titles = this._index.titles; var terms = this._index.terms; - var objects = this._index.objects; var objtypes = this._index.objtypes; - var objnames = this._index.objnames; var fileMap = {}; var files = null; // different result priorities @@ -173,39 +171,12 @@ var Search = { // lookup as object if (object != null) { - for (var prefix in objects) { - for (var name in objects[prefix]) { - 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]; - switch (match[2]) { - case 1: objectResults.push(result); break; - case 0: importantResults.push(result); break; - case 2: unimportantResults.push(result); break; - } - } - } - } + var results = this.performObjectSearch(object); + objectResults = results[0]; + importantResults = results[1]; + unimportantResults = results[2]; } - // sort results descending - objectResults.sort(function(a, b) { - return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); - }); - - importantResults.sort(function(a, b) { - return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); - }); - - unimportantResults.sort(function(a, b) { - return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); - }); - - // perform the search on the required terms for (var i = 0; i < searchterms.length; i++) { var word = searchterms[i]; @@ -325,6 +296,50 @@ var Search = { } } displayNextItem(); + }, + + performObjectSearch : function(object) { + var filenames = this._index.filenames; + var objects = this._index.objects; + var objnames = this._index.objnames; + var titles = this._index.titles; + + var importantResults = []; + var objectResults = []; + var unimportantResults = []; + + for (var prefix in objects) { + for (var name in objects[prefix]) { + 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]; + switch (match[2]) { + case 1: objectResults.push(result); break; + case 0: importantResults.push(result); break; + case 2: unimportantResults.push(result); break; + } + } + } + } + + // sort results descending + objectResults.sort(function(a, b) { + return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); + }); + + importantResults.sort(function(a, b) { + return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); + }); + + unimportantResults.sort(function(a, b) { + return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); + }); + + return [importantResults, objectResults, unimportantResults] } } |