jenkins-bot has submitted this change and it was merged. Change subject: Try interwiki search if we have less that N (default 3) results ......................................................................
Try interwiki search if we have less that N (default 3) results Bug: T118286 Change-Id: I87748776bd50872ccbda7a10ace9bf8d8c13376c (cherry picked from commit e775d148cb73ff7bf43a76f25cb1e03934fe31f2) --- M CirrusSearch.php M includes/CirrusSearch.php M includes/Search/ResultSet.php 3 files changed, 24 insertions(+), 11 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/CirrusSearch.php b/CirrusSearch.php index cf0d6a2..df60fbb 100644 --- a/CirrusSearch.php +++ b/CirrusSearch.php @@ -799,6 +799,11 @@ */ $wgCirrusSearchInterwikiProv = false; +/** + * If current wiki has less than this number of results, try to search other language wikis. + */ +$wgCirrusSearchInterwikiThreshold = 3; + $includes = __DIR__ . "/includes/"; $apiDir = $includes . 'Api/'; $buildDocument = $includes . 'BuildDocument/'; diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php index d275b3b..e083e77 100644 --- a/includes/CirrusSearch.php +++ b/includes/CirrusSearch.php @@ -95,7 +95,8 @@ return $matches; } - if ( $this->isFeatureEnabled( 'rewrite' ) && $matches->isQueryRewriteAllowed() ) { + if ( $this->isFeatureEnabled( 'rewrite' ) && + $matches->isQueryRewriteAllowed( $GLOBALS['wgCirrusSearchInterwikiThreshold'] ) ) { $matches = $this->searchTextSecondTry( $term, $matches ); } return $matches; @@ -140,11 +141,11 @@ return isset( $this->features[$feature] ) && $this->features[$feature]; } - private function searchTextSecondTry( $term, ResultSet $zeroResult ) { + private function searchTextSecondTry( $term, ResultSet $oldResult ) { // TODO: figure out who goes first - language or suggestion? - if ( $zeroResult->hasSuggestion() ) { - $rewritten = $zeroResult->getSuggestionQuery(); - $rewrittenSnippet = $zeroResult->getSuggestionSnippet(); + if ( $oldResult->numRows() == 0 && $oldResult->hasSuggestion() ) { + $rewritten = $oldResult->getSuggestionQuery(); + $rewrittenSnippet = $oldResult->getSuggestionSnippet(); $this->showSuggestion = false; $rewrittenResult = $this->searchTextReal( $rewritten ); if ( @@ -152,7 +153,12 @@ && $rewrittenResult->numRows() > 0 ) { $rewrittenResult->setRewrittenQuery( $rewritten, $rewrittenSnippet ); - return $rewrittenResult; + if ( $rewrittenResult->numRows() < $GLOBALS['wgCirrusSearchInterwikiThreshold'] ) { + // replace the result but still try the alt language + $oldResult = $rewrittenResult; + } else { + return $rewrittenResult; + } } } @@ -167,13 +173,13 @@ if ( $config ) { $matches = $this->searchTextReal( $term, $config ); if( $matches instanceof ResultSet && $matches->numRows() > 0 ) { - $zeroResult->addInterwikiResults( $matches, SearchResultSet::INLINE_RESULTS, $altWiki[1] ); + $oldResult->addInterwikiResults( $matches, SearchResultSet::INLINE_RESULTS, $altWiki[1] ); } } } // Don't have any other options yet. - return $zeroResult; + return $oldResult; } /** diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php index 0c0ab64..58cc2a7 100644 --- a/includes/Search/ResultSet.php +++ b/includes/Search/ResultSet.php @@ -60,14 +60,16 @@ } /** + * Is rewriting this query OK? + * @param int $threshold Minimum number of results to reach before rewriting is not allowed. * @return bool True when rewriting this query is allowed */ - public function isQueryRewriteAllowed() { - if ( $this->numRows() > 0 || $this->searchContainedSyntax() ) { + public function isQueryRewriteAllowed( $threshold = 1 ) { + if ( $this->numRows() >= $threshold || $this->searchContainedSyntax() ) { return false; } foreach ( $this->getInterwikiResults( SearchResultSet::SECONDARY_RESULTS ) as $resultSet ) { - if ( $resultSet->numRows() > 0 ) { + if ( $resultSet->numRows() >= $threshold ) { return false; } } -- To view, visit https://gerrit.wikimedia.org/r/254320 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I87748776bd50872ccbda7a10ace9bf8d8c13376c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: wmf/1.27.0-wmf.7 Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: DCausse <dcau...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Manybubbles <never...@wikimedia.org> Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits