[MediaWiki-commits] [Gerrit] mediawiki...CirrusSearch[master]: Support variants in prefixSearch
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/386025 ) Change subject: Support variants in prefixSearch .. Support variants in prefixSearch Change-Id: Ife0b519ef3a758924851e2351d8cfa5ef872ed5d --- M includes/CirrusSearch.php M includes/Searcher.php 2 files changed, 63 insertions(+), 39 deletions(-) Approvals: Tjones: Looks good to me, but someone else must approve Cindy-the-browser-test-bot: Looks good to me, but someone else must approve EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php index 930e82a..57d16fa 100644 --- a/includes/CirrusSearch.php +++ b/includes/CirrusSearch.php @@ -561,34 +561,34 @@ return parent::completionSearchBackend( $search ); } - if ( !$this->completionSuggesterEnabled( $this->config ) ) { - // Completion suggester is not enabled, fallback to - // default implementation - return $this->prefixSearch( $search ); - } - - if ( count( $this->namespaces ) != 1 || - reset( $this->namespaces ) != NS_MAIN - ) { - // for now, suggester only works for main namespace - return $this->prefixSearch( $search ); - } - - if ( isset( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] ) ) { - // Fallback to prefixsearch if the classic profile was selected. - if ( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] == self::COMPLETION_PREFIX_FALLBACK_PROFILE ) { - return $this->prefixSearch( $search ); - } - } - // Not really useful, mostly for testing purpose - $variants = $this->request->getArray( 'cirrusCompletionSuggesterVariant' ); + $variants = $this->request->getArray( 'cirrusCompletionVariant' ); if ( empty( $variants ) ) { global $wgContLang; $variants = $wgContLang->autoConvertToAllVariants( $search ); } elseif ( count( $variants ) > 3 ) { // We should not allow too many variants $variants = array_slice( $variants, 0, 3 ); + } + + if ( !$this->completionSuggesterEnabled( $this->config ) ) { + // Completion suggester is not enabled, fallback to + // default implementation + return $this->prefixSearch( $search, $variants ); + } + + if ( count( $this->namespaces ) != 1 || + reset( $this->namespaces ) != NS_MAIN + ) { + // for now, suggester only works for main namespace + return $this->prefixSearch( $search, $variants ); + } + + if ( isset( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] ) ) { + // Fallback to prefixsearch if the classic profile was selected. + if ( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] == self::COMPLETION_PREFIX_FALLBACK_PROFILE ) { + return $this->prefixSearch( $search, $variants ); + } } return $this->getSuggestions( $search, $variants, $this->config ); @@ -608,9 +608,10 @@ /** * Older prefix search. * @param string $search search text +* @param string[] $variants * @return SearchSuggestionSet */ - protected function prefixSearch( $search ) { + protected function prefixSearch( $search, $variants ) { $searcher = new Searcher( $this->connection, $this->offset, $this->limit, $this->config, $this->namespaces ); if ( $search ) { @@ -621,7 +622,7 @@ } try { - $status = $searcher->prefixSearch( $search ); + $status = $searcher->prefixSearch( $search, $variants ); } catch ( ApiUsageException $e ) { if ( defined( 'MW_API' ) ) { throw $e; diff --git a/includes/Searcher.php b/includes/Searcher.php index 7c44a63..a6d883f 100644 --- a/includes/Searcher.php +++ b/includes/Searcher.php @@ -251,9 +251,10 @@ /** * Perform a prefix search. * @param string $term text by which to search +* $param string[] $variants variants to search for * @return Status status containing results defined by resultsType on success */ - public function prefixSearch( $term ) { +
[MediaWiki-commits] [Gerrit] mediawiki...CirrusSearch[master]: Support variants in prefixSearch
DCausse has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/386025 ) Change subject: Support variants in prefixSearch .. Support variants in prefixSearch Change-Id: Ife0b519ef3a758924851e2351d8cfa5ef872ed5d --- M includes/CirrusSearch.php M includes/Searcher.php 2 files changed, 63 insertions(+), 39 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/25/386025/1 diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php index 930e82a..57d16fa 100644 --- a/includes/CirrusSearch.php +++ b/includes/CirrusSearch.php @@ -561,34 +561,34 @@ return parent::completionSearchBackend( $search ); } - if ( !$this->completionSuggesterEnabled( $this->config ) ) { - // Completion suggester is not enabled, fallback to - // default implementation - return $this->prefixSearch( $search ); - } - - if ( count( $this->namespaces ) != 1 || - reset( $this->namespaces ) != NS_MAIN - ) { - // for now, suggester only works for main namespace - return $this->prefixSearch( $search ); - } - - if ( isset( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] ) ) { - // Fallback to prefixsearch if the classic profile was selected. - if ( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] == self::COMPLETION_PREFIX_FALLBACK_PROFILE ) { - return $this->prefixSearch( $search ); - } - } - // Not really useful, mostly for testing purpose - $variants = $this->request->getArray( 'cirrusCompletionSuggesterVariant' ); + $variants = $this->request->getArray( 'cirrusCompletionVariant' ); if ( empty( $variants ) ) { global $wgContLang; $variants = $wgContLang->autoConvertToAllVariants( $search ); } elseif ( count( $variants ) > 3 ) { // We should not allow too many variants $variants = array_slice( $variants, 0, 3 ); + } + + if ( !$this->completionSuggesterEnabled( $this->config ) ) { + // Completion suggester is not enabled, fallback to + // default implementation + return $this->prefixSearch( $search, $variants ); + } + + if ( count( $this->namespaces ) != 1 || + reset( $this->namespaces ) != NS_MAIN + ) { + // for now, suggester only works for main namespace + return $this->prefixSearch( $search, $variants ); + } + + if ( isset( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] ) ) { + // Fallback to prefixsearch if the classic profile was selected. + if ( $this->features[SearchEngine::COMPLETION_PROFILE_TYPE] == self::COMPLETION_PREFIX_FALLBACK_PROFILE ) { + return $this->prefixSearch( $search, $variants ); + } } return $this->getSuggestions( $search, $variants, $this->config ); @@ -608,9 +608,10 @@ /** * Older prefix search. * @param string $search search text +* @param string[] $variants * @return SearchSuggestionSet */ - protected function prefixSearch( $search ) { + protected function prefixSearch( $search, $variants ) { $searcher = new Searcher( $this->connection, $this->offset, $this->limit, $this->config, $this->namespaces ); if ( $search ) { @@ -621,7 +622,7 @@ } try { - $status = $searcher->prefixSearch( $search ); + $status = $searcher->prefixSearch( $search, $variants ); } catch ( ApiUsageException $e ) { if ( defined( 'MW_API' ) ) { throw $e; diff --git a/includes/Searcher.php b/includes/Searcher.php index 7c44a63..a6d883f 100644 --- a/includes/Searcher.php +++ b/includes/Searcher.php @@ -251,9 +251,10 @@ /** * Perform a prefix search. * @param string $term text by which to search +* $param string[] $variants variants to search for * @return Status status containing results defined by resultsType on success */ - public function prefixSearch( $term ) { + public function prefixSearch( $term, $variants = [] ) { $this->checkTitleSearchRequestLength( $term );