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

Change subject: In prefix search weight title matches higher
......................................................................


In prefix search weight title matches higher

This causes title matches to be weighted higher than redirect matches.  If you
don't do that then you get too many crazy results on enwiki.

Bug: 73636
Change-Id: If4aef14368c89391d623475604dc3077f0d022e2
(cherry picked from commit de7a1dd23da4e8b8242d130422fa3fa0c47a59cb)
---
M CirrusSearch.php
M includes/Searcher.php
M tests/browser/features/prefix_search.feature
M tests/browser/features/support/hooks.rb
4 files changed, 25 insertions(+), 3 deletions(-)

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



diff --git a/CirrusSearch.php b/CirrusSearch.php
index 8b68420..0d17ef0 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -249,6 +249,14 @@
        'file_text' => 0.5,
 );
 
+// Weight of fields in prefix search.  It is safe to change these at any time.
+$wgCirrusSearchPrefixWeights = array(
+       'title' => 10,
+       'redirect' => 1,
+       'title_asciifolding' => 7,
+       'redirect_asciifolding' => 0.7,
+);
+
 // Enable building and using of "all" fields that contain multiple copies of 
other fields
 // for weighting.  These all fields exist entirely to speed up the full_text 
query type by
 // baking the weights above into a single field.  This is useful because it 
drasticly
diff --git a/includes/Searcher.php b/includes/Searcher.php
index b671256..59a690f 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -277,7 +277,8 @@
         * @param Status(mixed) status containing results defined by 
resultsType on success
         */
        public function prefixSearch( $search ) {
-               global $wgCirrusSearchPrefixSearchStartsWithAnyWord;
+               global $wgCirrusSearchPrefixSearchStartsWithAnyWord,
+                       $wgCirrusSearchPrefixWeights;
 
                $profiler = new ProfileSection( __METHOD__ );
 
@@ -297,8 +298,10 @@
                        $this->query = new \Elastica\Query\MultiMatch();
                        $this->query->setQuery( $search );
                        $this->query->setFields( array(
-                               'title.prefix^10', 'redirect.title.prefix^10',
-                               'title.prefix_asciifolding', 
'redirect.title.prefix_asciifolding'
+                               'title.prefix^' . $wgCirrusSearchPrefixWeights[ 
'title' ],
+                               'redirect.title.prefix^' . 
$wgCirrusSearchPrefixWeights[ 'redirect' ],
+                               'title.prefix_asciifolding^' . 
$wgCirrusSearchPrefixWeights[ 'title_asciifolding' ],
+                               'redirect.title.prefix_asciifolding^' . 
$wgCirrusSearchPrefixWeights[ 'redirect_asciifolding' ],
                        ) );
                }
                $this->boostTemplates = self::getDefaultBoostTemplates();
diff --git a/tests/browser/features/prefix_search.feature 
b/tests/browser/features/prefix_search.feature
index 5954919..d417d77 100644
--- a/tests/browser/features/prefix_search.feature
+++ b/tests/browser/features/prefix_search.feature
@@ -53,6 +53,13 @@
     When I click the search button
     Then I am on a page titled User talk:Search Engine Optimization 
Redirecttest
 
+  @redirect
+  Scenario: Prefix search ranks redirects under title matches
+    When I type PrefixRedirectRanking into the search box
+    Then suggestions should appear
+      And PrefixRedirectRanking 1 is the first suggestion
+      And PrefixRedirectRanking 2 is the second suggestion
+
   @accent_squashing @accented_namespace
   Scenario Outline: Search suggestions with accents
     When I type <term> into the search box
diff --git a/tests/browser/features/support/hooks.rb 
b/tests/browser/features/support/hooks.rb
index 4de78e3..eaa2a0a 100644
--- a/tests/browser/features/support/hooks.rb
+++ b/tests/browser/features/support/hooks.rb
@@ -384,6 +384,10 @@
       And a page named Search Engine Optimization Redirecttest exists
       And a page named Redirecttest Yay exists
       And a page named User_talk:Search Engine Optimization Redirecttest exists
+      And a page named PrefixRedirectRanking 1 exists
+      And a page named LinksToPrefixRedirectRanking 1 exists with contents 
[[PrefixRedirectRanking 1]]
+      And a page named TargetOfPrefixRedirectRanking 2 exists
+      And a page named PrefixRedirectRanking 2 exists with contents #REDIRECT 
[[TargetOfPrefixRedirectRanking 2]]
         )
   end
   redirect = true

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

Gerrit-MessageType: merged
Gerrit-Change-Id: If4aef14368c89391d623475604dc3077f0d022e2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: wmf/1.25wmf8
Gerrit-Owner: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to