aboutsummaryrefslogtreecommitdiffstats
path: root/_static/searchtools.js
diff options
context:
space:
mode:
Diffstat (limited to '_static/searchtools.js')
-rw-r--r--_static/searchtools.js53
1 files changed, 41 insertions, 12 deletions
diff --git a/_static/searchtools.js b/_static/searchtools.js
index 0e794fd..a51e0dc 100644
--- a/_static/searchtools.js
+++ b/_static/searchtools.js
@@ -2,14 +2,15 @@
2 * searchtools.js_t 2 * searchtools.js_t
3 * ~~~~~~~~~~~~~~~~ 3 * ~~~~~~~~~~~~~~~~
4 * 4 *
5 * Sphinx JavaScript utilties for the full-text search. 5 * Sphinx JavaScript utilities for the full-text search.
6 * 6 *
7 * :copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS. 7 * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
8 * :license: BSD, see LICENSE for details. 8 * :license: BSD, see LICENSE for details.
9 * 9 *
10 */ 10 */
11 11
12 12
13/* Non-minified version JS is _stemmer.js if file is provided */
13/** 14/**
14 * Porter Stemmer 15 * Porter Stemmer
15 */ 16 */
@@ -323,7 +324,7 @@ var Search = {
323 var searchterms = []; 324 var searchterms = [];
324 var excluded = []; 325 var excluded = [];
325 var hlterms = []; 326 var hlterms = [];
326 var tmp = query.split(/\s+/); 327 var tmp = query.split(/\W+/);
327 var objectterms = []; 328 var objectterms = [];
328 for (i = 0; i < tmp.length; i++) { 329 for (i = 0; i < tmp.length; i++) {
329 if (tmp[i] !== "") { 330 if (tmp[i] !== "") {
@@ -373,8 +374,7 @@ var Search = {
373 } 374 }
374 375
375 // lookup as search terms in fulltext 376 // lookup as search terms in fulltext
376 results = results.concat(this.performTermsSearch(searchterms, excluded, terms, Scorer.term)) 377 results = results.concat(this.performTermsSearch(searchterms, excluded, terms, titleterms));
377 .concat(this.performTermsSearch(searchterms, excluded, titleterms, Scorer.title));
378 378
379 // let the scorer override scores with a custom scoring function 379 // let the scorer override scores with a custom scoring function
380 if (Scorer.score) { 380 if (Scorer.score) {
@@ -538,23 +538,47 @@ var Search = {
538 /** 538 /**
539 * search for full-text terms in the index 539 * search for full-text terms in the index
540 */ 540 */
541 performTermsSearch : function(searchterms, excluded, terms, score) { 541 performTermsSearch : function(searchterms, excluded, terms, titleterms) {
542 var filenames = this._index.filenames; 542 var filenames = this._index.filenames;
543 var titles = this._index.titles; 543 var titles = this._index.titles;
544 544
545 var i, j, file, files; 545 var i, j, file;
546 var fileMap = {}; 546 var fileMap = {};
547 var scoreMap = {};
547 var results = []; 548 var results = [];
548 549
549 // perform the search on the required terms 550 // perform the search on the required terms
550 for (i = 0; i < searchterms.length; i++) { 551 for (i = 0; i < searchterms.length; i++) {
551 var word = searchterms[i]; 552 var word = searchterms[i];
553 var files = [];
554 var _o = [
555 {files: terms[word], score: Scorer.term},
556 {files: titleterms[word], score: Scorer.title}
557 ];
558
552 // no match but word was a required one 559 // no match but word was a required one
553 if ((files = terms[word]) === undefined) 560 if ($u.every(_o, function(o){return o.files === undefined;})) {
554 break; 561 break;
555 if (files.length === undefined) {
556 files = [files];
557 } 562 }
563 // found search word in contents
564 $u.each(_o, function(o) {
565 var _files = o.files;
566 if (_files === undefined)
567 return
568
569 if (_files.length === undefined)
570 _files = [_files];
571 files = files.concat(_files);
572
573 // set score for the word in each file to Scorer.term
574 for (j = 0; j < _files.length; j++) {
575 file = _files[j];
576 if (!(file in scoreMap))
577 scoreMap[file] = {}
578 scoreMap[file][word] = o.score;
579 }
580 });
581
558 // create the mapping 582 // create the mapping
559 for (j = 0; j < files.length; j++) { 583 for (j = 0; j < files.length; j++) {
560 file = files[j]; 584 file = files[j];
@@ -576,7 +600,9 @@ var Search = {
576 // ensure that none of the excluded terms is in the search result 600 // ensure that none of the excluded terms is in the search result
577 for (i = 0; i < excluded.length; i++) { 601 for (i = 0; i < excluded.length; i++) {
578 if (terms[excluded[i]] == file || 602 if (terms[excluded[i]] == file ||
579 $u.contains(terms[excluded[i]] || [], file)) { 603 titleterms[excluded[i]] == file ||
604 $u.contains(terms[excluded[i]] || [], file) ||
605 $u.contains(titleterms[excluded[i]] || [], file)) {
580 valid = false; 606 valid = false;
581 break; 607 break;
582 } 608 }
@@ -584,6 +610,9 @@ var Search = {
584 610
585 // if we have still a valid result we can add it to the result list 611 // if we have still a valid result we can add it to the result list
586 if (valid) { 612 if (valid) {
613 // select one (max) score for the file.
614 // for better ranking, we should calculate ranking by using words statistics like basic tf-idf...
615 var score = $u.max($u.map(fileMap[file], function(w){return scoreMap[file][w]}));
587 results.push([filenames[file], titles[file], '', null, score]); 616 results.push([filenames[file], titles[file], '', null, score]);
588 } 617 }
589 } 618 }
@@ -594,7 +623,7 @@ var Search = {
594 * helper function to return a node containing the 623 * helper function to return a node containing the
595 * search summary for a given text. keywords is a list 624 * search summary for a given text. keywords is a list
596 * of stemmed words, hlwords is the list of normal, unstemmed 625 * of stemmed words, hlwords is the list of normal, unstemmed
597 * words. the first one is used to find the occurance, the 626 * words. the first one is used to find the occurrence, the
598 * latter for highlighting it. 627 * latter for highlighting it.
599 */ 628 */
600 makeSearchSummary : function(text, keywords, hlwords) { 629 makeSearchSummary : function(text, keywords, hlwords) {