DCausse has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/313007

Change subject: Do not run exact db match if offset is > 0
......................................................................

Do not run exact db match if offset is > 0

When scrolling results on prefix search api the exact Title
match is always at pos 0 even if we want to scroll the results
by setting offset to > 0.

Change-Id: Ib02c9d3e479d739e6fe79014d962db50b6fd9de8
---
M includes/PrefixSearch.php
M includes/search/SearchEngine.php
2 files changed, 24 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/07/313007/1

diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php
index 98bc885..df271cc 100644
--- a/includes/PrefixSearch.php
+++ b/includes/PrefixSearch.php
@@ -182,12 +182,18 @@
                ) ) {
                        return $this->titles( $this->defaultSearchBackend( 
$namespaces, $search, $limit, $offset ) );
                }
-               return $this->strings( $this->handleResultFromHook( $srchres, 
$namespaces, $search, $limit ) );
+               return $this->strings( $this->handleResultFromHook( $srchres, 
$namespaces, $search, $limit, $offset ) );
        }
 
-       private function handleResultFromHook( $srchres, $namespaces, $search, 
$limit ) {
-               $rescorer = new SearchExactMatchRescorer();
-               return $rescorer->rescore( $search, $namespaces, $srchres, 
$limit );
+       private function handleResultFromHook( $srchres, $namespaces, $search, 
$limit, $offset ) {
+               if ( $offset === 0 ) {
+                       // Only perform exact db match if offset === 0
+                       // This is still far from perfect but at least avoid 
returning the
+                       // same title afain and again while scrolling if it 
matches the db.
+                       $rescorer = new SearchExactMatchRescorer();
+                       $srchres = $rescorer->rescore( $search, $namespaces, 
$srchres, $limit );
+               }
+               return $srchres;
        }
 
        /**
diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index 696facb..90bfebd 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -547,13 +547,20 @@
                        return $sugg->getSuggestedTitle()->getPrefixedText();
                } );
 
-               // Rescore results with an exact title match
-               // NOTE: in some cases like cross-namespace redirects
-               // (frequently used as shortcuts e.g. WP:WP on huwiki) some
-               // backends like Cirrus will return no results. We should still
-               // try an exact title match to workaround this limitation
-               $rescorer = new SearchExactMatchRescorer();
-               $rescoredResults = $rescorer->rescore( $search, 
$this->namespaces, $results, $this->limit );
+               if ( $this->offset === 0 ) {
+                       // Rescore results with an exact title match
+                       // NOTE: in some cases like cross-namespace redirects
+                       // (frequently used as shortcuts e.g. WP:WP on huwiki) 
some
+                       // backends like Cirrus will return no results. We 
should still
+                       // try an exact title match to workaround this 
limitation
+                       $rescorer = new SearchExactMatchRescorer();
+                       $rescoredResults = $rescorer->rescore( $search, 
$this->namespaces, $results, $this->limit );
+               } else {
+                       // No need to rescore if offset is not 0
+                       // The exact match must have been returned at position 0
+                       // if it existed.
+                       $rescoredResults = $results;
+               }
 
                if ( count( $rescoredResults ) > 0 ) {
                        $found = array_search( $rescoredResults[0], $results );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib02c9d3e479d739e6fe79014d962db50b6fd9de8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>

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

Reply via email to