44 *
55 * Sphinx JavaScript utilties for the full-text search.
66 *
7- * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
7+ * :copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
88 * :license: BSD, see LICENSE for details.
99 *
1010 */
1111
1212
13- /* Non-minified version JS is _stemmer.js if file is provided */
1413/**
1514 * Porter Stemmer
1615 */
@@ -374,7 +373,8 @@ var Search = {
374373 }
375374
376375 // lookup as search terms in fulltext
377- results = results . concat ( this . performTermsSearch ( searchterms , excluded , terms , titleterms ) ) ;
376+ results = results . concat ( this . performTermsSearch ( searchterms , excluded , terms , Scorer . term ) )
377+ . concat ( this . performTermsSearch ( searchterms , excluded , titleterms , Scorer . title ) ) ;
378378
379379 // let the scorer override scores with a custom scoring function
380380 if ( Scorer . score ) {
@@ -538,47 +538,23 @@ var Search = {
538538 /**
539539 * search for full-text terms in the index
540540 */
541- performTermsSearch : function ( searchterms , excluded , terms , titleterms ) {
541+ performTermsSearch : function ( searchterms , excluded , terms , score ) {
542542 var filenames = this . _index . filenames ;
543543 var titles = this . _index . titles ;
544544
545- var i , j , file ;
545+ var i , j , file , files ;
546546 var fileMap = { } ;
547- var scoreMap = { } ;
548547 var results = [ ] ;
549548
550549 // perform the search on the required terms
551550 for ( i = 0 ; i < searchterms . length ; i ++ ) {
552551 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-
559552 // no match but word was a required one
560- if ( $u . every ( _o , function ( o ) { return o . files === undefined ; } ) ) {
553+ if ( ( files = terms [ word ] ) === undefined )
561554 break ;
555+ if ( files . length === undefined ) {
556+ files = [ files ] ;
562557 }
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-
582558 // create the mapping
583559 for ( j = 0 ; j < files . length ; j ++ ) {
584560 file = files [ j ] ;
@@ -600,19 +576,14 @@ var Search = {
600576 // ensure that none of the excluded terms is in the search result
601577 for ( i = 0 ; i < excluded . length ; i ++ ) {
602578 if ( terms [ excluded [ i ] ] == file ||
603- titleterms [ excluded [ i ] ] == file ||
604- $u . contains ( terms [ excluded [ i ] ] || [ ] , file ) ||
605- $u . contains ( titleterms [ excluded [ i ] ] || [ ] , file ) ) {
579+ $u . contains ( terms [ excluded [ i ] ] || [ ] , file ) ) {
606580 valid = false ;
607581 break ;
608582 }
609583 }
610584
611585 // if we have still a valid result we can add it to the result list
612586 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 ] } ) ) ;
616587 results . push ( [ filenames [ file ] , titles [ file ] , '' , null , score ] ) ;
617588 }
618589 }
0 commit comments