EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/319779
Change subject: Make SearchConfig non-optional in the Searcher constructor ...................................................................... Make SearchConfig non-optional in the Searcher constructor In a followup patch I needed access to the configuration in InterwikiSearcher::__construct before calling parent::__construct. Could have added the SearchConfig to only InterwikiSearcher, but it seemed like things might be a little easier to follow if we always passed the relevant configuration from the edges of the extension into the center anyways. Change-Id: I7ed08f4e00b78765d94d85d52fc2a187ffe7bbbe --- M includes/CirrusSearch.php M includes/Dump.php M includes/Hooks.php M includes/InterwikiSearcher.php M includes/Maintenance/Validators/CacheWarmersValidator.php M includes/Searcher.php M maintenance/saneitize.php 7 files changed, 16 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/79/319779/1 diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php index c6302c7..900be4a 100644 --- a/includes/CirrusSearch.php +++ b/includes/CirrusSearch.php @@ -155,7 +155,7 @@ * @return ResultSet|null|Status results, no results, or error respectively */ public function searchText( $term ) { - $config = null; + $config = $this->config; if ( $this->request && $this->request->getVal( 'cirrusLang' ) ) { $config = new SearchConfig( $this->request->getVal( 'cirrusLang' ) ); } @@ -272,7 +272,7 @@ $rewritten = $oldResult->getSuggestionQuery(); $rewrittenSnippet = $oldResult->getSuggestionSnippet(); $this->showSuggestion = false; - $rewrittenResult = $this->searchTextReal( $rewritten ); + $rewrittenResult = $this->searchTextReal( $rewritten, $this->config ); if ( $rewrittenResult instanceof ResultSet && $rewrittenResult->numRows() > 0 @@ -329,10 +329,8 @@ * local wiki (e.g. avoid searching on commons) * @return null|Status|ResultSet */ - protected function searchTextReal( $term, SearchConfig $config = null, $forceLocal = false ) { - if ( $config ) { - $this->indexBaseName = $config->get( SearchConfig::INDEX_BASE_NAME ); - } + protected function searchTextReal( $term, SearchConfig $config, $forceLocal = false ) { + $this->indexBaseName = $config->get( SearchConfig::INDEX_BASE_NAME ); $searcher = new Searcher( $this->connection, $this->offset, $this->limit, $config, $this->namespaces, null, $this->indexBaseName ); @@ -416,7 +414,7 @@ ( $dumpQuery || $dumpResult || method_exists( $result, 'addInterwikiResults' ) ) ) { - $iwSearch = new InterwikiSearcher( $this->connection, $this->namespaces ); + $iwSearch = new InterwikiSearcher( $this->connection, $config, $this->namespaces ); $iwSearch->setReturnQuery( $dumpQuery ); $iwSearch->setDumpResult( $dumpResult ); $iwSearch->setReturnExplain( $returnExplain ); @@ -641,7 +639,7 @@ * @return SearchSuggestionSet */ protected function prefixSearch( $search ) { - $searcher = new Searcher( $this->connection, $this->offset, $this->limit, null, $this->namespaces ); + $searcher = new Searcher( $this->connection, $this->offset, $this->limit, $this->config, $this->namespaces ); if ( $search ) { $searcher->setResultsType( new FancyTitleResultsType( 'prefix' ) ); diff --git a/includes/Dump.php b/includes/Dump.php index f316003..a13cb2b 100644 --- a/includes/Dump.php +++ b/includes/Dump.php @@ -37,7 +37,8 @@ ->makeConfig( 'CirrusSearch' ); /** @suppress PhanTypeMismatchArgument $config is actually a SearchConfig */ $conn = new Connection( $config ); - $searcher = new Searcher( $conn, 0, 0, null, [], $this->getUser() ); + /** @suppress PhanTypeMismatchArgument $config is actually a SearchConfig */ + $searcher = new Searcher( $conn, 0, 0, $config, [], $this->getUser() ); /** @suppress PhanUndeclaredMethod Phan doesn't know $config is a SearchConfig */ $docId = $config->makeId( $this->getTitle()->getArticleID() ); diff --git a/includes/Hooks.php b/includes/Hooks.php index 5e13c98..6071979 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -551,7 +551,7 @@ * @return boolean */ public static function prefixSearchExtractNamespace( &$namespaces, &$search ) { - $searcher = new Searcher( self::getConnection(), 0, 1, null, $namespaces ); + $searcher = new Searcher( self::getConnection(), 0, 1, self::getConfig(), $namespaces ); $searcher->updateNamespacesFromQuery( $search ); $namespaces = $searcher->getSearchContext()->getNamespaces(); return false; @@ -573,7 +573,7 @@ $user = RequestContext::getMain()->getUser(); // Ask for the first 50 results we see. If there are more than that too bad. - $searcher = new Searcher( self::getConnection(), 0, 50, null, [ $title->getNamespace() ], $user ); + $searcher = new Searcher( self::getConnection(), 0, 50, self::getConfig(), [ $title->getNamespace() ], $user ); if ( $title->getNamespace() === NS_MAIN ) { $searcher->updateNamespacesFromQuery( $term ); } else { diff --git a/includes/InterwikiSearcher.php b/includes/InterwikiSearcher.php index 30f5c8c..a62ed62 100644 --- a/includes/InterwikiSearcher.php +++ b/includes/InterwikiSearcher.php @@ -39,18 +39,19 @@ /** * Constructor * @param Connection $connection + * @param SearchConfig $config * @param int[]|null $namespaces Namespace numbers to search, or null for all of them * @param User|null $user * @param string $index Base name for index to search from, defaults to $wgCirrusSearchIndexBaseName */ - public function __construct( Connection $connection, array $namespaces = null, User $user = null ) { + public function __construct( Connection $connection, SearchConfig $config, array $namespaces = null, User $user = null ) { // Only allow core namespaces. We can't be sure any others exist if ( $namespaces !== null ) { $namespaces = array_filter( $namespaces, function( $namespace ) { return $namespace <= 15; } ); } - parent::__construct( $connection, 0, self::MAX_RESULTS, null, $namespaces, $user ); + parent::__construct( $connection, 0, self::MAX_RESULTS, $config, $namespaces, $user ); } /** diff --git a/includes/Maintenance/Validators/CacheWarmersValidator.php b/includes/Maintenance/Validators/CacheWarmersValidator.php index 2220273..51bffdc 100644 --- a/includes/Maintenance/Validators/CacheWarmersValidator.php +++ b/includes/Maintenance/Validators/CacheWarmersValidator.php @@ -85,7 +85,7 @@ $this->maint->getConnection(), 0, 50, // 0 offset 50 limit is the default for searching so we try it too. - null, + $this->maint->getSearchConfig(), [], // array() for namespaces will stop us from eagerly caching the namespace // filters. That is probably OK because most searches don't use one. diff --git a/includes/Searcher.php b/includes/Searcher.php index 3413eee..c1e7f1e 100644 --- a/includes/Searcher.php +++ b/includes/Searcher.php @@ -133,16 +133,8 @@ * @param User|null $user user for which this search is being performed. Attached to slow request logs. * @param string|boolean $index Base name for index to search from, defaults to $wgCirrusSearchIndexBaseName */ - public function __construct( Connection $conn, $offset, $limit, SearchConfig $config = null, array $namespaces = null, + public function __construct( Connection $conn, $offset, $limit, SearchConfig $config, array $namespaces = null, User $user = null, $index = false ) { - - if ( is_null( $config ) ) { - // @todo connection has an embedded config ... reuse that? somehow should - // at least ensure they are the same. - $config = MediaWikiServices::getInstance() - ->getConfigFactory() - ->makeConfig( 'CirrusSearch' ); - } parent::__construct( $conn, $user, $config->get( 'CirrusSearchSlowSearch' ), $config->get( 'CirrusSearchExtraBackendLatency' ) ); $this->config = $config; diff --git a/maintenance/saneitize.php b/maintenance/saneitize.php index e6625c4..f9f0dd2 100644 --- a/maintenance/saneitize.php +++ b/maintenance/saneitize.php @@ -152,7 +152,7 @@ $remediator = new PrintingRemediator( $remediator ); } // This searcher searches all indexes for the current wiki. - $searcher = new Searcher( $this->getConnection(), 0, 0, null, [], null ); + $searcher = new Searcher( $this->getConnection(), 0, 0, $this->getSearchConfig(), [], null ); $this->checker = new Checker( $this->getSearchConfig(), $this->getConnection(), -- To view, visit https://gerrit.wikimedia.org/r/319779 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7ed08f4e00b78765d94d85d52fc2a187ffe7bbbe Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits