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

Change subject: Prefer title for prefix search match
......................................................................


Prefer title for prefix search match

If a page has both a title and a redirect match then return the title instead
of the redirect.

Bug: 63627
Change-Id: I078c4767024cd584ab28ec2e1f4dde3e26d774f0
(cherry picked from commit 4da200bc179883fec91f379c6b1ae422482f92eb)
---
M includes/ResultsType.php
M tests/browser/features/prefix_search.feature
M tests/browser/features/step_definitions/search_steps.rb
M tests/browser/features/support/hooks.rb
M tests/browser/features/support/pages/search_page.rb
5 files changed, 34 insertions(+), 16 deletions(-)

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



diff --git a/includes/ResultsType.php b/includes/ResultsType.php
index e3cbecd..686b442 100644
--- a/includes/ResultsType.php
+++ b/includes/ResultsType.php
@@ -95,22 +95,25 @@
                        // Now we have to use the highlights to figure out 
whether it was the title or the redirect
                        // that matched.  It is kind of a shame we can't really 
give the highlighting to the client
                        // though.
-                       if ( isset( $highlights[ 
"redirect.title.$this->matchedAnalyzer" ] ) ) {
-                               // The match was against a redirect so we 
should replace the $title with one that
-                               // represents the redirect.
-                               // The first step is to strip the actual 
highlighting from the title.
-                               $redirectTitle = $highlights[ 
"redirect.title.$this->matchedAnalyzer" ][ 0 ];
-                               $redirectTitle = str_replace( 
Searcher::HIGHLIGHT_PRE, '', $redirectTitle );
-                               $redirectTitle = str_replace( 
Searcher::HIGHLIGHT_POST, '', $redirectTitle );
+                       if ( !isset( $highlights[ 
"title.$this->matchedAnalyzer" ] ) ) {
+                               // The match wasn't against the title, so it 
better be against a redirect.
+                               if ( isset( $highlights[ 
"redirect.title.$this->matchedAnalyzer" ] ) ) {
+                                       // The match was against a redirect so 
we should replace the $title with one that
+                                       // represents the redirect.
+                                       // The first step is to strip the 
actual highlighting from the title.
+                                       $redirectTitle = $highlights[ 
"redirect.title.$this->matchedAnalyzer" ][ 0 ];
+                                       $redirectTitle = str_replace( 
Searcher::HIGHLIGHT_PRE, '', $redirectTitle );
+                                       $redirectTitle = str_replace( 
Searcher::HIGHLIGHT_POST, '', $redirectTitle );
 
-                               // Instead of getting the redirect's real 
namespace we're going to just use the namespace
-                               // of the title.  This is not great but OK 
given that we can't find cross namespace
-                               // redirects properly any way.
-                               $title = Title::makeTitle( $r->namespace, 
$redirectTitle );
-                       } else if ( !isset( $highlights[ 
"title.$this->matchedAnalyzer" ] ) ) {
-                               // We're not really sure where the match came 
from so lets just pretend it was the title?
-                               wfDebugLog( 'CirrusSearch', "Title search 
result type hit a match but we can't " .
-                                       "figure out what caused the match:  
$r->namespace:$r->title");
+                                       // Instead of getting the redirect's 
real namespace we're going to just use the namespace
+                                       // of the title.  This is not great but 
OK given that we can't find cross namespace
+                                       // redirects properly any way.
+                                       $title = Title::makeTitle( 
$r->namespace, $redirectTitle );
+                               } else {
+                                       // We're not really sure where the 
match came from so lets just pretend it was the title.
+                                       wfDebugLog( 'CirrusSearch', "Title 
search result type hit a match but we can't " .
+                                               "figure out what caused the 
match:  $r->namespace:$r->title");
+                               }
                        }
                        if ( $this->getText ) {
                                $title = $title->getPrefixedText();
diff --git a/tests/browser/features/prefix_search.feature 
b/tests/browser/features/prefix_search.feature
index 5fbc9b3..99f9d46 100644
--- a/tests/browser/features/prefix_search.feature
+++ b/tests/browser/features/prefix_search.feature
@@ -40,3 +40,10 @@
     And SEO Redirecttest is the first suggestion
     When I click the search button
     Then I am on a page titled Search Engine Optimization Redirecttest
+
+  @prefix @redirect
+  Scenario: Prefix search includes redirects
+    When I type Redirecttest Y into the search box
+    Then suggestions should appear
+    And Redirecttest Yay is the first suggestion
+   And Redirecttest Yikes is not in the suggestions
diff --git a/tests/browser/features/step_definitions/search_steps.rb 
b/tests/browser/features/step_definitions/search_steps.rb
index d9aba09..c386647 100644
--- a/tests/browser/features/step_definitions/search_steps.rb
+++ b/tests/browser/features/step_definitions/search_steps.rb
@@ -92,6 +92,11 @@
     on(SearchPage).one_result.should == title
   end
 end
+Then(/^(.+) is not in the suggestions$/) do |title|
+  on(SearchPage).all_results_elements.each do |result|
+    result.text.should_not == title
+  end
+end
 Then(/^I should be offered to search for (.+)$/) do |term|
   on(SearchPage).search_special.should == "containing...\n" + term
 end
diff --git a/tests/browser/features/support/hooks.rb 
b/tests/browser/features/support/hooks.rb
index 49816fe..ce7a3f8 100644
--- a/tests/browser/features/support/hooks.rb
+++ b/tests/browser/features/support/hooks.rb
@@ -308,9 +308,11 @@
   if !$go_options
     steps %Q{
       Given a page named SEO Redirecttest exists with contents #REDIRECT 
[[Search Engine Optimization Redirecttest]]
+      And a page named Redirecttest Yikes exists with contents #REDIRECT 
[[Redirecttest Yay]]
       And wait 3 seconds
       And a page named Seo Redirecttest exists
       And a page named Search Engine Optimization Redirecttest exists
+      And a page named Redirecttest Yay exists
     }
   end
   $go_options = true
diff --git a/tests/browser/features/support/pages/search_page.rb 
b/tests/browser/features/support/pages/search_page.rb
index f09313e..7f7c2ab 100644
--- a/tests/browser/features/support/pages/search_page.rb
+++ b/tests/browser/features/support/pages/search_page.rb
@@ -1,9 +1,10 @@
 class SearchPage
   include PageObject
 
-  div(:one_result, class: "suggestions-result")
   button(:search_button, id: "searchButton")
   text_field(:search_input, id: "searchInput")
   div(:search_results, class: "suggestions-results")
   div(:search_special, class: "suggestions-special")
+  div(:one_result, class: "suggestions-result")
+  links(:all_results, class: "suggestions-result"){ |page| 
page.search_results_element.link_elements }
 end

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I078c4767024cd584ab28ec2e1f4dde3e26d774f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: wmf/1.23wmf21
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