Fix highlighting of results when the search result does not return termMatches
[lhc/web/wiklou.git] / includes / search / SearchResult.php
index 453211b..1d28691 100644 (file)
@@ -142,13 +142,6 @@ class SearchResult {
                return $this->mImage;
        }
 
-       /**
-        * @return float|null If not supported
-        */
-       function getScore() {
-               return null;
-       }
-
        /**
         * Lazy initialization of article text from DB
         */
@@ -173,11 +166,16 @@ class SearchResult {
 
                // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
                list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs();
+
                $h = new SearchHighlighter();
-               if ( $wgAdvancedSearchHighlighting ) {
-                       return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars );
+               if ( count( $terms ) > 0 ) {
+                       if ( $wgAdvancedSearchHighlighting ) {
+                               return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars );
+                       } else {
+                               return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars );
+                       }
                } else {
-                       return $h->highlightSimple( $this->mText, $terms, $contextlines, $contextchars );
+                       return $h->highlightNone( $this->mText, $contextlines, $contextchars );
                }
        }