docs/_build/html/_static/searchtools.js

Fri, 11 May 2012 13:27:13 +0200

author
ulalume3 <binietoglou@imaa.cnr.it>
date
Fri, 11 May 2012 13:27:13 +0200
changeset 12
3171dc8d75e7
parent 11
79fea4145278
permissions
-rw-r--r--

Changed markdown to Restructured text.

ulalume3@11 1 /*
ulalume3@11 2 * searchtools.js_t
ulalume3@11 3 * ~~~~~~~~~~~~~~~~
ulalume3@11 4 *
ulalume3@11 5 * Sphinx JavaScript utilties for the full-text search.
ulalume3@11 6 *
ulalume3@11 7 * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
ulalume3@11 8 * :license: BSD, see LICENSE for details.
ulalume3@11 9 *
ulalume3@11 10 */
ulalume3@11 11
ulalume3@11 12 /**
ulalume3@11 13 * helper function to return a node containing the
ulalume3@11 14 * search summary for a given text. keywords is a list
ulalume3@11 15 * of stemmed words, hlwords is the list of normal, unstemmed
ulalume3@11 16 * words. the first one is used to find the occurance, the
ulalume3@11 17 * latter for highlighting it.
ulalume3@11 18 */
ulalume3@11 19
ulalume3@11 20 jQuery.makeSearchSummary = function(text, keywords, hlwords) {
ulalume3@11 21 var textLower = text.toLowerCase();
ulalume3@11 22 var start = 0;
ulalume3@11 23 $.each(keywords, function() {
ulalume3@11 24 var i = textLower.indexOf(this.toLowerCase());
ulalume3@11 25 if (i > -1)
ulalume3@11 26 start = i;
ulalume3@11 27 });
ulalume3@11 28 start = Math.max(start - 120, 0);
ulalume3@11 29 var excerpt = ((start > 0) ? '...' : '') +
ulalume3@11 30 $.trim(text.substr(start, 240)) +
ulalume3@11 31 ((start + 240 - text.length) ? '...' : '');
ulalume3@11 32 var rv = $('<div class="context"></div>').text(excerpt);
ulalume3@11 33 $.each(hlwords, function() {
ulalume3@11 34 rv = rv.highlightText(this, 'highlighted');
ulalume3@11 35 });
ulalume3@11 36 return rv;
ulalume3@11 37 }
ulalume3@11 38
ulalume3@11 39
ulalume3@11 40 /**
ulalume3@11 41 * Porter Stemmer
ulalume3@11 42 */
ulalume3@11 43 var Stemmer = function() {
ulalume3@11 44
ulalume3@11 45 var step2list = {
ulalume3@11 46 ational: 'ate',
ulalume3@11 47 tional: 'tion',
ulalume3@11 48 enci: 'ence',
ulalume3@11 49 anci: 'ance',
ulalume3@11 50 izer: 'ize',
ulalume3@11 51 bli: 'ble',
ulalume3@11 52 alli: 'al',
ulalume3@11 53 entli: 'ent',
ulalume3@11 54 eli: 'e',
ulalume3@11 55 ousli: 'ous',
ulalume3@11 56 ization: 'ize',
ulalume3@11 57 ation: 'ate',
ulalume3@11 58 ator: 'ate',
ulalume3@11 59 alism: 'al',
ulalume3@11 60 iveness: 'ive',
ulalume3@11 61 fulness: 'ful',
ulalume3@11 62 ousness: 'ous',
ulalume3@11 63 aliti: 'al',
ulalume3@11 64 iviti: 'ive',
ulalume3@11 65 biliti: 'ble',
ulalume3@11 66 logi: 'log'
ulalume3@11 67 };
ulalume3@11 68
ulalume3@11 69 var step3list = {
ulalume3@11 70 icate: 'ic',
ulalume3@11 71 ative: '',
ulalume3@11 72 alize: 'al',
ulalume3@11 73 iciti: 'ic',
ulalume3@11 74 ical: 'ic',
ulalume3@11 75 ful: '',
ulalume3@11 76 ness: ''
ulalume3@11 77 };
ulalume3@11 78
ulalume3@11 79 var c = "[^aeiou]"; // consonant
ulalume3@11 80 var v = "[aeiouy]"; // vowel
ulalume3@11 81 var C = c + "[^aeiouy]*"; // consonant sequence
ulalume3@11 82 var V = v + "[aeiou]*"; // vowel sequence
ulalume3@11 83
ulalume3@11 84 var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0
ulalume3@11 85 var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1
ulalume3@11 86 var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1
ulalume3@11 87 var s_v = "^(" + C + ")?" + v; // vowel in stem
ulalume3@11 88
ulalume3@11 89 this.stemWord = function (w) {
ulalume3@11 90 var stem;
ulalume3@11 91 var suffix;
ulalume3@11 92 var firstch;
ulalume3@11 93 var origword = w;
ulalume3@11 94
ulalume3@11 95 if (w.length < 3)
ulalume3@11 96 return w;
ulalume3@11 97
ulalume3@11 98 var re;
ulalume3@11 99 var re2;
ulalume3@11 100 var re3;
ulalume3@11 101 var re4;
ulalume3@11 102
ulalume3@11 103 firstch = w.substr(0,1);
ulalume3@11 104 if (firstch == "y")
ulalume3@11 105 w = firstch.toUpperCase() + w.substr(1);
ulalume3@11 106
ulalume3@11 107 // Step 1a
ulalume3@11 108 re = /^(.+?)(ss|i)es$/;
ulalume3@11 109 re2 = /^(.+?)([^s])s$/;
ulalume3@11 110
ulalume3@11 111 if (re.test(w))
ulalume3@11 112 w = w.replace(re,"$1$2");
ulalume3@11 113 else if (re2.test(w))
ulalume3@11 114 w = w.replace(re2,"$1$2");
ulalume3@11 115
ulalume3@11 116 // Step 1b
ulalume3@11 117 re = /^(.+?)eed$/;
ulalume3@11 118 re2 = /^(.+?)(ed|ing)$/;
ulalume3@11 119 if (re.test(w)) {
ulalume3@11 120 var fp = re.exec(w);
ulalume3@11 121 re = new RegExp(mgr0);
ulalume3@11 122 if (re.test(fp[1])) {
ulalume3@11 123 re = /.$/;
ulalume3@11 124 w = w.replace(re,"");
ulalume3@11 125 }
ulalume3@11 126 }
ulalume3@11 127 else if (re2.test(w)) {
ulalume3@11 128 var fp = re2.exec(w);
ulalume3@11 129 stem = fp[1];
ulalume3@11 130 re2 = new RegExp(s_v);
ulalume3@11 131 if (re2.test(stem)) {
ulalume3@11 132 w = stem;
ulalume3@11 133 re2 = /(at|bl|iz)$/;
ulalume3@11 134 re3 = new RegExp("([^aeiouylsz])\\1$");
ulalume3@11 135 re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
ulalume3@11 136 if (re2.test(w))
ulalume3@11 137 w = w + "e";
ulalume3@11 138 else if (re3.test(w)) {
ulalume3@11 139 re = /.$/;
ulalume3@11 140 w = w.replace(re,"");
ulalume3@11 141 }
ulalume3@11 142 else if (re4.test(w))
ulalume3@11 143 w = w + "e";
ulalume3@11 144 }
ulalume3@11 145 }
ulalume3@11 146
ulalume3@11 147 // Step 1c
ulalume3@11 148 re = /^(.+?)y$/;
ulalume3@11 149 if (re.test(w)) {
ulalume3@11 150 var fp = re.exec(w);
ulalume3@11 151 stem = fp[1];
ulalume3@11 152 re = new RegExp(s_v);
ulalume3@11 153 if (re.test(stem))
ulalume3@11 154 w = stem + "i";
ulalume3@11 155 }
ulalume3@11 156
ulalume3@11 157 // Step 2
ulalume3@11 158 re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
ulalume3@11 159 if (re.test(w)) {
ulalume3@11 160 var fp = re.exec(w);
ulalume3@11 161 stem = fp[1];
ulalume3@11 162 suffix = fp[2];
ulalume3@11 163 re = new RegExp(mgr0);
ulalume3@11 164 if (re.test(stem))
ulalume3@11 165 w = stem + step2list[suffix];
ulalume3@11 166 }
ulalume3@11 167
ulalume3@11 168 // Step 3
ulalume3@11 169 re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
ulalume3@11 170 if (re.test(w)) {
ulalume3@11 171 var fp = re.exec(w);
ulalume3@11 172 stem = fp[1];
ulalume3@11 173 suffix = fp[2];
ulalume3@11 174 re = new RegExp(mgr0);
ulalume3@11 175 if (re.test(stem))
ulalume3@11 176 w = stem + step3list[suffix];
ulalume3@11 177 }
ulalume3@11 178
ulalume3@11 179 // Step 4
ulalume3@11 180 re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
ulalume3@11 181 re2 = /^(.+?)(s|t)(ion)$/;
ulalume3@11 182 if (re.test(w)) {
ulalume3@11 183 var fp = re.exec(w);
ulalume3@11 184 stem = fp[1];
ulalume3@11 185 re = new RegExp(mgr1);
ulalume3@11 186 if (re.test(stem))
ulalume3@11 187 w = stem;
ulalume3@11 188 }
ulalume3@11 189 else if (re2.test(w)) {
ulalume3@11 190 var fp = re2.exec(w);
ulalume3@11 191 stem = fp[1] + fp[2];
ulalume3@11 192 re2 = new RegExp(mgr1);
ulalume3@11 193 if (re2.test(stem))
ulalume3@11 194 w = stem;
ulalume3@11 195 }
ulalume3@11 196
ulalume3@11 197 // Step 5
ulalume3@11 198 re = /^(.+?)e$/;
ulalume3@11 199 if (re.test(w)) {
ulalume3@11 200 var fp = re.exec(w);
ulalume3@11 201 stem = fp[1];
ulalume3@11 202 re = new RegExp(mgr1);
ulalume3@11 203 re2 = new RegExp(meq1);
ulalume3@11 204 re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
ulalume3@11 205 if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
ulalume3@11 206 w = stem;
ulalume3@11 207 }
ulalume3@11 208 re = /ll$/;
ulalume3@11 209 re2 = new RegExp(mgr1);
ulalume3@11 210 if (re.test(w) && re2.test(w)) {
ulalume3@11 211 re = /.$/;
ulalume3@11 212 w = w.replace(re,"");
ulalume3@11 213 }
ulalume3@11 214
ulalume3@11 215 // and turn initial Y back to y
ulalume3@11 216 if (firstch == "y")
ulalume3@11 217 w = firstch.toLowerCase() + w.substr(1);
ulalume3@11 218 return w;
ulalume3@11 219 }
ulalume3@11 220 }
ulalume3@11 221
ulalume3@11 222
ulalume3@11 223 /**
ulalume3@11 224 * Search Module
ulalume3@11 225 */
ulalume3@11 226 var Search = {
ulalume3@11 227
ulalume3@11 228 _index : null,
ulalume3@11 229 _queued_query : null,
ulalume3@11 230 _pulse_status : -1,
ulalume3@11 231
ulalume3@11 232 init : function() {
ulalume3@11 233 var params = $.getQueryParameters();
ulalume3@11 234 if (params.q) {
ulalume3@11 235 var query = params.q[0];
ulalume3@11 236 $('input[name="q"]')[0].value = query;
ulalume3@11 237 this.performSearch(query);
ulalume3@11 238 }
ulalume3@11 239 },
ulalume3@11 240
ulalume3@11 241 loadIndex : function(url) {
ulalume3@11 242 $.ajax({type: "GET", url: url, data: null, success: null,
ulalume3@11 243 dataType: "script", cache: true});
ulalume3@11 244 },
ulalume3@11 245
ulalume3@11 246 setIndex : function(index) {
ulalume3@11 247 var q;
ulalume3@11 248 this._index = index;
ulalume3@11 249 if ((q = this._queued_query) !== null) {
ulalume3@11 250 this._queued_query = null;
ulalume3@11 251 Search.query(q);
ulalume3@11 252 }
ulalume3@11 253 },
ulalume3@11 254
ulalume3@11 255 hasIndex : function() {
ulalume3@11 256 return this._index !== null;
ulalume3@11 257 },
ulalume3@11 258
ulalume3@11 259 deferQuery : function(query) {
ulalume3@11 260 this._queued_query = query;
ulalume3@11 261 },
ulalume3@11 262
ulalume3@11 263 stopPulse : function() {
ulalume3@11 264 this._pulse_status = 0;
ulalume3@11 265 },
ulalume3@11 266
ulalume3@11 267 startPulse : function() {
ulalume3@11 268 if (this._pulse_status >= 0)
ulalume3@11 269 return;
ulalume3@11 270 function pulse() {
ulalume3@11 271 Search._pulse_status = (Search._pulse_status + 1) % 4;
ulalume3@11 272 var dotString = '';
ulalume3@11 273 for (var i = 0; i < Search._pulse_status; i++)
ulalume3@11 274 dotString += '.';
ulalume3@11 275 Search.dots.text(dotString);
ulalume3@11 276 if (Search._pulse_status > -1)
ulalume3@11 277 window.setTimeout(pulse, 500);
ulalume3@11 278 };
ulalume3@11 279 pulse();
ulalume3@11 280 },
ulalume3@11 281
ulalume3@11 282 /**
ulalume3@11 283 * perform a search for something
ulalume3@11 284 */
ulalume3@11 285 performSearch : function(query) {
ulalume3@11 286 // create the required interface elements
ulalume3@11 287 this.out = $('#search-results');
ulalume3@11 288 this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
ulalume3@11 289 this.dots = $('<span></span>').appendTo(this.title);
ulalume3@11 290 this.status = $('<p style="display: none"></p>').appendTo(this.out);
ulalume3@11 291 this.output = $('<ul class="search"/>').appendTo(this.out);
ulalume3@11 292
ulalume3@11 293 $('#search-progress').text(_('Preparing search...'));
ulalume3@11 294 this.startPulse();
ulalume3@11 295
ulalume3@11 296 // index already loaded, the browser was quick!
ulalume3@11 297 if (this.hasIndex())
ulalume3@11 298 this.query(query);
ulalume3@11 299 else
ulalume3@11 300 this.deferQuery(query);
ulalume3@11 301 },
ulalume3@11 302
ulalume3@11 303 query : function(query) {
ulalume3@11 304 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"];
ulalume3@11 305
ulalume3@11 306 // Stem the searchterms and add them to the correct list
ulalume3@11 307 var stemmer = new Stemmer();
ulalume3@11 308 var searchterms = [];
ulalume3@11 309 var excluded = [];
ulalume3@11 310 var hlterms = [];
ulalume3@11 311 var tmp = query.split(/\s+/);
ulalume3@11 312 var objectterms = [];
ulalume3@11 313 for (var i = 0; i < tmp.length; i++) {
ulalume3@11 314 if (tmp[i] != "") {
ulalume3@11 315 objectterms.push(tmp[i].toLowerCase());
ulalume3@11 316 }
ulalume3@11 317
ulalume3@11 318 if ($u.indexOf(stopwords, tmp[i]) != -1 || tmp[i].match(/^\d+$/) ||
ulalume3@11 319 tmp[i] == "") {
ulalume3@11 320 // skip this "word"
ulalume3@11 321 continue;
ulalume3@11 322 }
ulalume3@11 323 // stem the word
ulalume3@11 324 var word = stemmer.stemWord(tmp[i]).toLowerCase();
ulalume3@11 325 // select the correct list
ulalume3@11 326 if (word[0] == '-') {
ulalume3@11 327 var toAppend = excluded;
ulalume3@11 328 word = word.substr(1);
ulalume3@11 329 }
ulalume3@11 330 else {
ulalume3@11 331 var toAppend = searchterms;
ulalume3@11 332 hlterms.push(tmp[i].toLowerCase());
ulalume3@11 333 }
ulalume3@11 334 // only add if not already in the list
ulalume3@11 335 if (!$.contains(toAppend, word))
ulalume3@11 336 toAppend.push(word);
ulalume3@11 337 };
ulalume3@11 338 var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" "));
ulalume3@11 339
ulalume3@11 340 // console.debug('SEARCH: searching for:');
ulalume3@11 341 // console.info('required: ', searchterms);
ulalume3@11 342 // console.info('excluded: ', excluded);
ulalume3@11 343
ulalume3@11 344 // prepare search
ulalume3@11 345 var filenames = this._index.filenames;
ulalume3@11 346 var titles = this._index.titles;
ulalume3@11 347 var terms = this._index.terms;
ulalume3@11 348 var fileMap = {};
ulalume3@11 349 var files = null;
ulalume3@11 350 // different result priorities
ulalume3@11 351 var importantResults = [];
ulalume3@11 352 var objectResults = [];
ulalume3@11 353 var regularResults = [];
ulalume3@11 354 var unimportantResults = [];
ulalume3@11 355 $('#search-progress').empty();
ulalume3@11 356
ulalume3@11 357 // lookup as object
ulalume3@11 358 for (var i = 0; i < objectterms.length; i++) {
ulalume3@11 359 var others = [].concat(objectterms.slice(0,i),
ulalume3@11 360 objectterms.slice(i+1, objectterms.length))
ulalume3@11 361 var results = this.performObjectSearch(objectterms[i], others);
ulalume3@11 362 // Assume first word is most likely to be the object,
ulalume3@11 363 // other words more likely to be in description.
ulalume3@11 364 // Therefore put matches for earlier words first.
ulalume3@11 365 // (Results are eventually used in reverse order).
ulalume3@11 366 objectResults = results[0].concat(objectResults);
ulalume3@11 367 importantResults = results[1].concat(importantResults);
ulalume3@11 368 unimportantResults = results[2].concat(unimportantResults);
ulalume3@11 369 }
ulalume3@11 370
ulalume3@11 371 // perform the search on the required terms
ulalume3@11 372 for (var i = 0; i < searchterms.length; i++) {
ulalume3@11 373 var word = searchterms[i];
ulalume3@11 374 // no match but word was a required one
ulalume3@11 375 if ((files = terms[word]) == null)
ulalume3@11 376 break;
ulalume3@11 377 if (files.length == undefined) {
ulalume3@11 378 files = [files];
ulalume3@11 379 }
ulalume3@11 380 // create the mapping
ulalume3@11 381 for (var j = 0; j < files.length; j++) {
ulalume3@11 382 var file = files[j];
ulalume3@11 383 if (file in fileMap)
ulalume3@11 384 fileMap[file].push(word);
ulalume3@11 385 else
ulalume3@11 386 fileMap[file] = [word];
ulalume3@11 387 }
ulalume3@11 388 }
ulalume3@11 389
ulalume3@11 390 // now check if the files don't contain excluded terms
ulalume3@11 391 for (var file in fileMap) {
ulalume3@11 392 var valid = true;
ulalume3@11 393
ulalume3@11 394 // check if all requirements are matched
ulalume3@11 395 if (fileMap[file].length != searchterms.length)
ulalume3@11 396 continue;
ulalume3@11 397
ulalume3@11 398 // ensure that none of the excluded terms is in the
ulalume3@11 399 // search result.
ulalume3@11 400 for (var i = 0; i < excluded.length; i++) {
ulalume3@11 401 if (terms[excluded[i]] == file ||
ulalume3@11 402 $.contains(terms[excluded[i]] || [], file)) {
ulalume3@11 403 valid = false;
ulalume3@11 404 break;
ulalume3@11 405 }
ulalume3@11 406 }
ulalume3@11 407
ulalume3@11 408 // if we have still a valid result we can add it
ulalume3@11 409 // to the result list
ulalume3@11 410 if (valid)
ulalume3@11 411 regularResults.push([filenames[file], titles[file], '', null]);
ulalume3@11 412 }
ulalume3@11 413
ulalume3@11 414 // delete unused variables in order to not waste
ulalume3@11 415 // memory until list is retrieved completely
ulalume3@11 416 delete filenames, titles, terms;
ulalume3@11 417
ulalume3@11 418 // now sort the regular results descending by title
ulalume3@11 419 regularResults.sort(function(a, b) {
ulalume3@11 420 var left = a[1].toLowerCase();
ulalume3@11 421 var right = b[1].toLowerCase();
ulalume3@11 422 return (left > right) ? -1 : ((left < right) ? 1 : 0);
ulalume3@11 423 });
ulalume3@11 424
ulalume3@11 425 // combine all results
ulalume3@11 426 var results = unimportantResults.concat(regularResults)
ulalume3@11 427 .concat(objectResults).concat(importantResults);
ulalume3@11 428
ulalume3@11 429 // print the results
ulalume3@11 430 var resultCount = results.length;
ulalume3@11 431 function displayNextItem() {
ulalume3@11 432 // results left, load the summary and display it
ulalume3@11 433 if (results.length) {
ulalume3@11 434 var item = results.pop();
ulalume3@11 435 var listItem = $('<li style="display:none"></li>');
ulalume3@11 436 if (DOCUMENTATION_OPTIONS.FILE_SUFFIX == '') {
ulalume3@11 437 // dirhtml builder
ulalume3@11 438 var dirname = item[0] + '/';
ulalume3@11 439 if (dirname.match(/\/index\/$/)) {
ulalume3@11 440 dirname = dirname.substring(0, dirname.length-6);
ulalume3@11 441 } else if (dirname == 'index/') {
ulalume3@11 442 dirname = '';
ulalume3@11 443 }
ulalume3@11 444 listItem.append($('<a/>').attr('href',
ulalume3@11 445 DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
ulalume3@11 446 highlightstring + item[2]).html(item[1]));
ulalume3@11 447 } else {
ulalume3@11 448 // normal html builders
ulalume3@11 449 listItem.append($('<a/>').attr('href',
ulalume3@11 450 item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
ulalume3@11 451 highlightstring + item[2]).html(item[1]));
ulalume3@11 452 }
ulalume3@11 453 if (item[3]) {
ulalume3@11 454 listItem.append($('<span> (' + item[3] + ')</span>'));
ulalume3@11 455 Search.output.append(listItem);
ulalume3@11 456 listItem.slideDown(5, function() {
ulalume3@11 457 displayNextItem();
ulalume3@11 458 });
ulalume3@11 459 } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
ulalume3@11 460 $.get(DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' +
ulalume3@11 461 item[0] + '.txt', function(data) {
ulalume3@11 462 if (data != '') {
ulalume3@11 463 listItem.append($.makeSearchSummary(data, searchterms, hlterms));
ulalume3@11 464 Search.output.append(listItem);
ulalume3@11 465 }
ulalume3@11 466 listItem.slideDown(5, function() {
ulalume3@11 467 displayNextItem();
ulalume3@11 468 });
ulalume3@11 469 }, "text");
ulalume3@11 470 } else {
ulalume3@11 471 // no source available, just display title
ulalume3@11 472 Search.output.append(listItem);
ulalume3@11 473 listItem.slideDown(5, function() {
ulalume3@11 474 displayNextItem();
ulalume3@11 475 });
ulalume3@11 476 }
ulalume3@11 477 }
ulalume3@11 478 // search finished, update title and status message
ulalume3@11 479 else {
ulalume3@11 480 Search.stopPulse();
ulalume3@11 481 Search.title.text(_('Search Results'));
ulalume3@11 482 if (!resultCount)
ulalume3@11 483 Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
ulalume3@11 484 else
ulalume3@11 485 Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
ulalume3@11 486 Search.status.fadeIn(500);
ulalume3@11 487 }
ulalume3@11 488 }
ulalume3@11 489 displayNextItem();
ulalume3@11 490 },
ulalume3@11 491
ulalume3@11 492 performObjectSearch : function(object, otherterms) {
ulalume3@11 493 var filenames = this._index.filenames;
ulalume3@11 494 var objects = this._index.objects;
ulalume3@11 495 var objnames = this._index.objnames;
ulalume3@11 496 var titles = this._index.titles;
ulalume3@11 497
ulalume3@11 498 var importantResults = [];
ulalume3@11 499 var objectResults = [];
ulalume3@11 500 var unimportantResults = [];
ulalume3@11 501
ulalume3@11 502 for (var prefix in objects) {
ulalume3@11 503 for (var name in objects[prefix]) {
ulalume3@11 504 var fullname = (prefix ? prefix + '.' : '') + name;
ulalume3@11 505 if (fullname.toLowerCase().indexOf(object) > -1) {
ulalume3@11 506 var match = objects[prefix][name];
ulalume3@11 507 var objname = objnames[match[1]][2];
ulalume3@11 508 var title = titles[match[0]];
ulalume3@11 509 // If more than one term searched for, we require other words to be
ulalume3@11 510 // found in the name/title/description
ulalume3@11 511 if (otherterms.length > 0) {
ulalume3@11 512 var haystack = (prefix + ' ' + name + ' ' +
ulalume3@11 513 objname + ' ' + title).toLowerCase();
ulalume3@11 514 var allfound = true;
ulalume3@11 515 for (var i = 0; i < otherterms.length; i++) {
ulalume3@11 516 if (haystack.indexOf(otherterms[i]) == -1) {
ulalume3@11 517 allfound = false;
ulalume3@11 518 break;
ulalume3@11 519 }
ulalume3@11 520 }
ulalume3@11 521 if (!allfound) {
ulalume3@11 522 continue;
ulalume3@11 523 }
ulalume3@11 524 }
ulalume3@11 525 var descr = objname + _(', in ') + title;
ulalume3@11 526 anchor = match[3];
ulalume3@11 527 if (anchor == '')
ulalume3@11 528 anchor = fullname;
ulalume3@11 529 else if (anchor == '-')
ulalume3@11 530 anchor = objnames[match[1]][1] + '-' + fullname;
ulalume3@11 531 result = [filenames[match[0]], fullname, '#'+anchor, descr];
ulalume3@11 532 switch (match[2]) {
ulalume3@11 533 case 1: objectResults.push(result); break;
ulalume3@11 534 case 0: importantResults.push(result); break;
ulalume3@11 535 case 2: unimportantResults.push(result); break;
ulalume3@11 536 }
ulalume3@11 537 }
ulalume3@11 538 }
ulalume3@11 539 }
ulalume3@11 540
ulalume3@11 541 // sort results descending
ulalume3@11 542 objectResults.sort(function(a, b) {
ulalume3@11 543 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
ulalume3@11 544 });
ulalume3@11 545
ulalume3@11 546 importantResults.sort(function(a, b) {
ulalume3@11 547 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
ulalume3@11 548 });
ulalume3@11 549
ulalume3@11 550 unimportantResults.sort(function(a, b) {
ulalume3@11 551 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);
ulalume3@11 552 });
ulalume3@11 553
ulalume3@11 554 return [importantResults, objectResults, unimportantResults]
ulalume3@11 555 }
ulalume3@11 556 }
ulalume3@11 557
ulalume3@11 558 $(document).ready(function() {
ulalume3@11 559 Search.init();
ulalume3@11 560 });

mercurial