aboutsummaryrefslogtreecommitdiffstats
path: root/doc/_themes/pysidedocs/static/searchtools.js
diff options
context:
space:
mode:
Diffstat (limited to 'doc/_themes/pysidedocs/static/searchtools.js')
-rw-r--r--doc/_themes/pysidedocs/static/searchtools.js117
1 files changed, 84 insertions, 33 deletions
diff --git a/doc/_themes/pysidedocs/static/searchtools.js b/doc/_themes/pysidedocs/static/searchtools.js
index e0226258a..dae92b5e5 100644
--- a/doc/_themes/pysidedocs/static/searchtools.js
+++ b/doc/_themes/pysidedocs/static/searchtools.js
@@ -1,3 +1,14 @@
+/*
+ * searchtools.js
+ * ~~~~~~~~~~~~~~
+ *
+ * Sphinx JavaScript utilties for the full-text search.
+ *
+ * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
/**
* helper function to return a node containing the
* search summary for a given text. keywords is a list
@@ -20,7 +31,7 @@ jQuery.makeSearchSummary = function(text, keywords, hlwords) {
((start + 240 - text.length) ? '...' : '');
var rv = $('<div class="context"></div>').text(excerpt);
$.each(hlwords, function() {
- rv = rv.highlightText(this, 'highlight');
+ rv = rv.highlightText(this, 'highlighted');
});
return rv;
}
@@ -226,9 +237,11 @@ var Search = {
}
},
- /**
- * Sets the index
- */
+ loadIndex : function(url) {
+ $.ajax({type: "GET", url: url, data: null, success: null,
+ dataType: "script", cache: true});
+ },
+
setIndex : function(index) {
var q;
this._index = index;
@@ -287,8 +300,13 @@ var Search = {
},
query : function(query) {
- // stem the searchterms and add them to the
- // correct list
+ var stopwords = ['and', 'then', 'into', 'it', 'as', 'are', 'in',
+ 'if', 'for', 'no', 'there', 'their', 'was', 'is',
+ 'be', 'to', 'that', 'but', 'they', 'not', 'such',
+ 'with', 'by', 'a', 'on', 'these', 'of', 'will',
+ 'this', 'near', 'the', 'or', 'at'];
+
+ // stem the searchterms and add them to the correct list
var stemmer = new PorterStemmer();
var searchterms = [];
var excluded = [];
@@ -296,6 +314,11 @@ var Search = {
var tmp = query.split(/\s+/);
var object = (tmp.length == 1) ? tmp[0].toLowerCase() : null;
for (var i = 0; i < tmp.length; i++) {
+ if ($u.indexOf(stopwords, tmp[i]) != -1 || tmp[i].match(/^\d+$/) ||
+ tmp[i] == "") {
+ // skip this "word"
+ continue;
+ }
// stem the word
var word = stemmer.stemWord(tmp[i]).toLowerCase();
// select the correct list
@@ -313,39 +336,42 @@ var Search = {
};
var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" "));
- console.debug('SEARCH: searching for:');
- console.info('required: ', searchterms);
- console.info('excluded: ', excluded);
+ // console.debug('SEARCH: searching for:');
+ // console.info('required: ', searchterms);
+ // console.info('excluded: ', excluded);
// prepare search
var filenames = this._index.filenames;
var titles = this._index.titles;
var terms = this._index.terms;
- var descrefs = this._index.descrefs;
- var modules = this._index.modules;
- var desctypes = this._index.desctypes;
+ var objects = this._index.objects;
+ var objtypes = this._index.objtypes;
+ var objnames = this._index.objnames;
var fileMap = {};
var files = null;
+ // different result priorities
+ var importantResults = [];
var objectResults = [];
var regularResults = [];
+ var unimportantResults = [];
$('#search-progress').empty();
// lookup as object
if (object != null) {
- for (var module in modules) {
- if (module.indexOf(object) > -1) {
- fn = modules[module];
- descr = _('module, in ') + titles[fn];
- objectResults.push([filenames[fn], module, '#module-'+module, descr]);
- }
- }
- for (var prefix in descrefs) {
- for (var name in descrefs[prefix]) {
+ for (var prefix in objects) {
+ for (var name in objects[prefix]) {
var fullname = (prefix ? prefix + '.' : '') + name;
if (fullname.toLowerCase().indexOf(object) > -1) {
- match = descrefs[prefix][name];
- descr = desctypes[match[1]] + _(', in ') + titles[match[0]];
- objectResults.push([filenames[match[0]], fullname, '#'+fullname, descr]);
+ 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;
+ }
}
}
}
@@ -356,6 +382,14 @@ var Search = {
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++) {
@@ -411,8 +445,9 @@ var Search = {
return (left > right) ? -1 : ((left < right) ? 1 : 0);
});
- // combine both
- var results = regularResults.concat(objectResults);
+ // combine all results
+ var results = unimportantResults.concat(regularResults)
+ .concat(objectResults).concat(importantResults);
// print the results
var resultCount = results.length;
@@ -421,10 +456,23 @@ var Search = {
if (results.length) {
var item = results.pop();
var listItem = $('<li style="display:none"></li>');
- listItem.append($('<a/>').attr(
- 'href',
- item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
- highlightstring + item[2]).html(item[1]));
+ if (DOCUMENTATION_OPTIONS.FILE_SUFFIX == '') {
+ // dirhtml builder
+ var dirname = item[0] + '/';
+ if (dirname.match(/\/index\/$/)) {
+ dirname = dirname.substring(0, dirname.length-6);
+ } else if (dirname == 'index/') {
+ dirname = '';
+ }
+ listItem.append($('<a/>').attr('href',
+ DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
+ highlightstring + item[2]).html(item[1]));
+ } else {
+ // normal html builders
+ listItem.append($('<a/>').attr('href',
+ item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
+ highlightstring + item[2]).html(item[1]));
+ }
if (item[3]) {
listItem.append($('<span> (' + item[3] + ')</span>'));
Search.output.append(listItem);
@@ -432,9 +480,12 @@ var Search = {
displayNextItem();
});
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
- $.get('_sources/' + item[0] + '.txt', function(data) {
- listItem.append($.makeSearchSummary(data, searchterms, hlterms));
- Search.output.append(listItem);
+ $.get(DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' +
+ item[0] + '.txt', function(data) {
+ if (data != '') {
+ listItem.append($.makeSearchSummary(data, searchterms, hlterms));
+ Search.output.append(listItem);
+ }
listItem.slideDown(5, function() {
displayNextItem();
});