Commits

Luke Plant  committed c738a1b

Pulled object search routine into separate routine.

This makes it easier to re-use, and helps reduce the length of the main query
routine.

  • Participants
  • Parent commits 4b8d012

Comments (0)

Files changed (1)

File sphinx/themes/basic/static/searchtools.js_t

     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
 
     // 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];
       }
     }
     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]
   }
 }