jenkins-bot has submitted this change and it was merged.

Change subject: Skip highlighting we don't need
......................................................................


Skip highlighting we don't need

Slightly changes behavior: only displays redirect or section match if
there isn't a title match.  This might not be perfect but it is in line
with our goals to reduce IO usage.

DEPLOYMENT: This does nothing until the upgrade to Elasticsearch 1.3
and experimental-highlight 0.0.11 both of which are scheduled soon.

Change-Id: I58f031adedf875e0f2723c5c21c7ca91e1088893
---
M includes/Search/ResultsType.php
M tests/browser/features/highlighting.feature
2 files changed, 22 insertions(+), 15 deletions(-)

Approvals:
  Chad: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Search/ResultsType.php b/includes/Search/ResultsType.php
index 50fac2e..29fc9d9 100644
--- a/includes/Search/ResultsType.php
+++ b/includes/Search/ResultsType.php
@@ -220,13 +220,16 @@
                                'fragmenter' => 'none',
                                'number_of_fragments' => 1,
                        );
-                       $entireValueInListField = array(
+                       $redirectAndHeading = array(
                                'type' => 'experimental',
                                'fragmenter' => 'none',
                                'order' => 'score',
                                'number_of_fragments' => 1,
+                               'options' => array(
+                                       'skip_if_last_matched' => true,
+                               )
                        );
-                       $singleFragment = array(
+                       $remainingText = array(
                                'type' => 'experimental',
                                'number_of_fragments' => 1,
                                'fragmenter' => 'scan',
@@ -246,12 +249,13 @@
                                        // Setting this too low (like 50) can 
bury good snippets if the search
                                        // contains common words.
                                        'max_fragments_scored' => 5000,
+                                       'skip_if_last_matched' => true,
                                ),
                        );
                        if ( !( $this->highlightingConfig & 
self::HIGHLIGHT_WITH_DEFAULT_SIMILARITY ) ) {
                                $entireValue[ 'options' ][ 'default_similarity' 
] = false;
-                               $entireValueInListField[ 'options' ][ 
'default_similarity' ] = false;
-                               $singleFragment[ 'options' ][ 
'default_similarity' ] = false;
+                               $redirectAndHeading[ 'options' ][ 
'default_similarity' ] = false;
+                               $remainingText[ 'options' ][ 
'default_similarity' ] = false;
                        }
                } else {
                        $entireValue = array(
@@ -259,13 +263,13 @@
                                'type' => 'fvh',
                                'order' => 'score',
                        );
-                       $entireValueInListField = array(
+                       $redirectAndHeading = array(
                                'number_of_fragments' => 1, // Just one of the 
values in the list
                                'fragment_size' => 10000,   // We want the 
whole value but more than this is crazy
                                'type' => 'fvh',
                                'order' => 'score',
                        );
-                       $singleFragment = array(
+                       $remainingText = array(
                                'number_of_fragments' => 1, // Just one fragment
                                'fragment_size' => $wgCirrusSearchFragmentSize,
                                'type' => 'fvh',
@@ -273,8 +277,11 @@
                        );
                }
                // If there isn't a match just return a match sized chunk from 
the beginning of the page.
-               $text = $singleFragment;
+               $text = $remainingText;
                $text[ 'no_match_size' ] = $text[ 'fragment_size' ];
+               if ( isset( $text[ 'options' ][ 'skip_if_last_matched' ] ) ) {
+                       unset( $text[ 'options' ][ 'skip_if_last_matched' ] );
+               }
 
                $config =  array(
                        'pre_tags' => array( Searcher::HIGHLIGHT_PRE ),
@@ -285,14 +292,14 @@
                        $config[ 'fields' ][ 'title' ] = $entireValue;
                }
                if ( $this->highlightingConfig & self::HIGHLIGHT_ALT_TITLE ) {
-                       $config[ 'fields' ][ 'redirect.title' ] = 
$entireValueInListField;
-                       $config[ 'fields' ][ 'heading' ] = 
$entireValueInListField;
+                       $config[ 'fields' ][ 'redirect.title' ] = 
$redirectAndHeading;
+                       $config[ 'fields' ][ 'heading' ] = $redirectAndHeading;
                }
                if ( $this->highlightingConfig & self::HIGHLIGHT_SNIPPET ) {
                        $config[ 'fields' ][ 'text' ] = $text;
-                       $config[ 'fields' ][ 'auxiliary_text' ] = 
$singleFragment;
+                       $config[ 'fields' ][ 'auxiliary_text' ] = 
$remainingText;
                        if ( $this->highlightingConfig & 
self::HIGHLIGHT_FILE_TEXT ) {
-                               $config[ 'fields' ][ 'file_text' ] = 
$singleFragment;
+                               $config[ 'fields' ][ 'file_text' ] = 
$remainingText;
                        }
                }
                $config[ 'fields' ] = $this->addMatchedFields( $config[ 
'fields' ] );
diff --git a/tests/browser/features/highlighting.feature 
b/tests/browser/features/highlighting.feature
index da621be..490e2f4 100644
--- a/tests/browser/features/highlighting.feature
+++ b/tests/browser/features/highlighting.feature
@@ -60,7 +60,7 @@
 
   @headings
   Scenario: Found words are highlighted in headings even if they contain both 
a phrase and a non-phrase
-    When I search for "i am a" heading
+    When I search for i "am a heading"
     Then *I* *am* *a* *heading* is the highlighted alttitle of the first 
search result
 
   @headings
@@ -79,12 +79,12 @@
 
   @headings
   Scenario: The highest scoring heading is highlighted AND it doesn't contain 
html even if the heading on the page does
-    When I search for bold heading
+    When I search for "bold heading"
     Then I am a *bold* *heading* is the highlighted alttitle of the first 
search result
 
   @headings
   Scenario: HTML comments in headings are not highlighted
-    When I search for Heading with html comment
+    When I search for "Heading with html comment"
     And *Heading* *with* *html* *comment* is the highlighted alttitle of the 
first search result
 
   Scenario: Redirects are highlighted
@@ -107,7 +107,7 @@
 
   @references
   Scenario: References don't appear in highlighted section titles
-    When I search for Reference Section Highlight Test
+    When I search for "Reference Section"
     And *Reference* *Section* is the highlighted alttitle of the first search 
result
 
   @references

-- 
To view, visit https://gerrit.wikimedia.org/r/154898
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I58f031adedf875e0f2723c5c21c7ca91e1088893
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to