- Timestamp:
- 04/05/12 14:10:40 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/doc/_build/html/_static/searchtools.js
r13151 r13316 1 1 /* 2 * searchtools.js _t3 * ~~~~~~~~~~~~~~ ~~2 * searchtools.js 3 * ~~~~~~~~~~~~~~ 4 4 * 5 5 * Sphinx JavaScript utilties for the full-text search. 6 6 * 7 * :copyright: Copyright 2007-201 1by the Sphinx team, see AUTHORS.7 * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 8 * :license: BSD, see LICENSE for details. 9 9 * … … 37 37 } 38 38 39 40 39 /** 41 40 * Porter Stemmer 42 41 */ 43 var Stemmer = function() {42 var PorterStemmer = function() { 44 43 45 44 var step2list = { … … 302 301 303 302 query : function(query) { 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"]; 305 306 // Stem the searchterms and add them to the correct list 307 var stemmer = new Stemmer(); 303 var stopwords = ['and', 'then', 'into', 'it', 'as', 'are', 'in', 304 'if', 'for', 'no', 'there', 'their', 'was', 'is', 305 'be', 'to', 'that', 'but', 'they', 'not', 'such', 306 'with', 'by', 'a', 'on', 'these', 'of', 'will', 307 'this', 'near', 'the', 'or', 'at']; 308 309 // stem the searchterms and add them to the correct list 310 var stemmer = new PorterStemmer(); 308 311 var searchterms = []; 309 312 var excluded = []; 310 313 var hlterms = []; 311 314 var tmp = query.split(/\s+/); 312 var object terms = [];315 var object = (tmp.length == 1) ? tmp[0].toLowerCase() : null; 313 316 for (var i = 0; i < tmp.length; i++) { 314 if (tmp[i] != "") {315 objectterms.push(tmp[i].toLowerCase());316 }317 318 317 if ($u.indexOf(stopwords, tmp[i]) != -1 || tmp[i].match(/^\d+$/) || 319 318 tmp[i] == "") { … … 346 345 var titles = this._index.titles; 347 346 var terms = this._index.terms; 347 var objects = this._index.objects; 348 var objtypes = this._index.objtypes; 349 var objnames = this._index.objnames; 348 350 var fileMap = {}; 349 351 var files = null; … … 356 358 357 359 // lookup as object 358 for (var i = 0; i < objectterms.length; i++) { 359 var others = [].concat(objectterms.slice(0,i), 360 objectterms.slice(i+1, objectterms.length)) 361 var results = this.performObjectSearch(objectterms[i], others); 362 // Assume first word is most likely to be the object, 363 // other words more likely to be in description. 364 // Therefore put matches for earlier words first. 365 // (Results are eventually used in reverse order). 366 objectResults = results[0].concat(objectResults); 367 importantResults = results[1].concat(importantResults); 368 unimportantResults = results[2].concat(unimportantResults); 369 } 360 if (object != null) { 361 for (var prefix in objects) { 362 for (var name in objects[prefix]) { 363 var fullname = (prefix ? prefix + '.' : '') + name; 364 if (fullname.toLowerCase().indexOf(object) > -1) { 365 match = objects[prefix][name]; 366 descr = objnames[match[1]] + _(', in ') + titles[match[0]]; 367 // XXX the generated anchors are not generally correct 368 // XXX there may be custom prefixes 369 result = [filenames[match[0]], fullname, '#'+fullname, descr]; 370 switch (match[2]) { 371 case 1: objectResults.push(result); break; 372 case 0: importantResults.push(result); break; 373 case 2: unimportantResults.push(result); break; 374 } 375 } 376 } 377 } 378 } 379 380 // sort results descending 381 objectResults.sort(function(a, b) { 382 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); 383 }); 384 385 importantResults.sort(function(a, b) { 386 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); 387 }); 388 389 unimportantResults.sort(function(a, b) { 390 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); 391 }); 392 370 393 371 394 // perform the search on the required terms … … 467 490 displayNextItem(); 468 491 }); 469 } , "text");492 }); 470 493 } else { 471 494 // no source available, just display title … … 488 511 } 489 512 displayNextItem(); 490 },491 492 performObjectSearch : function(object, otherterms) {493 var filenames = this._index.filenames;494 var objects = this._index.objects;495 var objnames = this._index.objnames;496 var titles = this._index.titles;497 498 var importantResults = [];499 var objectResults = [];500 var unimportantResults = [];501 502 for (var prefix in objects) {503 for (var name in objects[prefix]) {504 var fullname = (prefix ? prefix + '.' : '') + name;505 if (fullname.toLowerCase().indexOf(object) > -1) {506 var match = objects[prefix][name];507 var objname = objnames[match[1]][2];508 var title = titles[match[0]];509 // If more than one term searched for, we require other words to be510 // found in the name/title/description511 if (otherterms.length > 0) {512 var haystack = (prefix + ' ' + name + ' ' +513 objname + ' ' + title).toLowerCase();514 var allfound = true;515 for (var i = 0; i < otherterms.length; i++) {516 if (haystack.indexOf(otherterms[i]) == -1) {517 allfound = false;518 break;519 }520 }521 if (!allfound) {522 continue;523 }524 }525 var descr = objname + _(', in ') + title;526 anchor = match[3];527 if (anchor == '')528 anchor = fullname;529 else if (anchor == '-')530 anchor = objnames[match[1]][1] + '-' + fullname;531 result = [filenames[match[0]], fullname, '#'+anchor, descr];532 switch (match[2]) {533 case 1: objectResults.push(result); break;534 case 0: importantResults.push(result); break;535 case 2: unimportantResults.push(result); break;536 }537 }538 }539 }540 541 // sort results descending542 objectResults.sort(function(a, b) {543 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);544 });545 546 importantResults.sort(function(a, b) {547 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);548 });549 550 unimportantResults.sort(function(a, b) {551 return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0);552 });553 554 return [importantResults, objectResults, unimportantResults]555 513 } 556 514 }
Note:
See TracChangeset
for help on using the changeset viewer.