From: jenkins-bot Date: Thu, 29 Sep 2016 16:45:02 +0000 (+0000) Subject: Merge "Do not run exact db match if offset is > 0" X-Git-Tag: 1.31.0-rc.0~5270 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=e09cc5413f81181a1fd8366c23baf148505489fe;hp=b1ae84ddf5f7dab3ad3bd1fc4d9ab34209bc3a59;p=lhc%2Fweb%2Fwiklou.git Merge "Do not run exact db match if offset is > 0" --- diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php index 98bc885c8b..f6c4147118 100644 --- a/includes/PrefixSearch.php +++ b/includes/PrefixSearch.php @@ -182,12 +182,20 @@ abstract class PrefixSearch { ) ) { 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 we avoid returning the + // same title afain and again when the user is scrolling with a query + // that matches a title in 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 696facba44..90bfebd213 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -547,13 +547,20 @@ abstract class SearchEngine { 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 );