DCausse has uploaded a new change for review. https://gerrit.wikimedia.org/r/320788
Change subject: Remove BC code after interwiki refactoring ...................................................................... Remove BC code after interwiki refactoring This removes all the BC codes needed to support interwiki searches on wikis where the wiki field is not fully populated. Bug: T141033 Change-Id: I9070e311ab1906038196dfda45ca1750cdceb9d0 --- M includes/CirrusSearch.php M includes/InterwikiSearcher.php M includes/Search/Result.php M includes/Search/ResultSet.php M includes/Search/ResultsType.php M includes/Search/TitleHelper.php M includes/SearchConfig.php M tests/unit/Search/ResultTest.php M tests/unit/Search/ResultsTypeTest.php 9 files changed, 26 insertions(+), 141 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/88/320788/1 diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php index c130f70..0ea09fe 100644 --- a/includes/CirrusSearch.php +++ b/includes/CirrusSearch.php @@ -369,7 +369,7 @@ $highlightingConfig ^= FullTextResultsType::HIGHLIGHT_FILE_TEXT; } - $resultsType = new FullTextResultsType( $config, $highlightingConfig ); + $resultsType = new FullTextResultsType( $highlightingConfig ); $searcher->setResultsType( $resultsType ); $status = $searcher->searchText( $term, $this->showSuggestion ); diff --git a/includes/InterwikiSearcher.php b/includes/InterwikiSearcher.php index 01ca55e..a51bd0d 100644 --- a/includes/InterwikiSearcher.php +++ b/includes/InterwikiSearcher.php @@ -128,18 +128,13 @@ $retval = []; $searches = []; - $resultsTypes = []; + // Note that this is a hack, $this->resultsType is not properly + // specialized to the interwiki use case, but because we are not + // returning load test results to the users that is acceptable. + if (!$this->isLoadTestEnabled ) { + $this->setResultsType( new InterwikiResultsType() ); + } foreach ( $sources as $interwiki => $index ) { - // Note that this is a hack, $this->resultsType is not properly - // specialized to the interwiki use case, but because we are not - // returning load test results to the users that is acceptable. - if (!$this->isLoadTestEnabled ) { - // TODO: remove when getWikiCode is removed. - // In theory we should be able to reuse the same - // Results type for all searches - $resultsTypes[$interwiki] = new InterwikiResultsType( $this->config->newInterwikiConfig( $index, false ) ); - $this->setResultsType( $resultsTypes[$interwiki] ); - } $this->indexBaseName = $index; $this->searchContext = clone $context; $search = $this->buildSearch(); @@ -150,7 +145,7 @@ } } - $results = $this->searchMulti( $searches, $resultsTypes ); + $results = $this->searchMulti( $searches ); if ( !$results->isOK() ) { return null; } diff --git a/includes/Search/Result.php b/includes/Search/Result.php index 19e7a5d..85289d5 100644 --- a/includes/Search/Result.php +++ b/includes/Search/Result.php @@ -5,7 +5,6 @@ use CirrusSearch\InterwikiSearcher; use CirrusSearch\Util; use CirrusSearch\Searcher; -use CirrusSearch\SearchConfig; use MediaWiki\Logger\LoggerFactory; use MWTimestamp; use SearchResult; @@ -50,8 +49,6 @@ private $textSnippet; /** @var bool */ private $isFileMatch = false; - /* @var SearchConfig */ - private $config; /* @var string result wiki */ private $wiki; /** @var string */ @@ -76,13 +73,11 @@ * * @param \Elastica\ResultSet $results containing all search results * @param \Elastica\Result $result containing the given search result - * @param string $interwiki Interwiki prefix, if any * @param \Elastica\Result $result containing information about the result this class should represent */ - public function __construct( $results, $result, SearchConfig $config ) { + public function __construct( $results, $result ) { global $wgCirrusSearchDevelOptions; $this->ignoreMissingRev = isset( $wgCirrusSearchDevelOptions['ignore_missing_rev'] ); - $this->config = $config; $this->namespace_text = $result->namespace_text; $this->wiki = $result->wiki; $this->docId = $result->getId(); @@ -365,12 +360,5 @@ */ public function getExplanation() { return $this->explanation; - } - - /** - * @return SearchConfig $config - */ - public function getConfig() { - return $this->config; } } diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php index aa32148..7b55cc8 100644 --- a/includes/Search/ResultSet.php +++ b/includes/Search/ResultSet.php @@ -3,7 +3,6 @@ namespace CirrusSearch\Search; use CirrusSearch\Searcher; -use CirrusSearch\SearchConfig; use SearchResultSet; /** @@ -58,11 +57,6 @@ private $searchContainedSyntax; /** - * @var SearchConfig - */ - private $config; - - /** * @var array */ private $interwikiResults = []; @@ -82,14 +76,12 @@ * @param string[] $suggestSuffixes * @param \Elastica\ResultSet $res * @param bool $searchContainedSyntax - * @param SearchConfig $config */ - public function __construct( array $suggestPrefixes, array $suggestSuffixes, \Elastica\ResultSet $res, $searchContainedSyntax, SearchConfig $config ) { + public function __construct( array $suggestPrefixes, array $suggestSuffixes, \Elastica\ResultSet $res, $searchContainedSyntax ) { $this->result = $res; $this->searchContainedSyntax = $searchContainedSyntax; $this->hits = $res->count(); $this->totalHits = $res->getTotalHits(); - $this->config = $config; $this->preCacheContainedTitles( $this->result ); $suggestion = $this->findSuggestion(); if ( $suggestion && ! $this->resultContainsFullyHighlightedMatch() ) { @@ -226,7 +218,7 @@ $current = $this->result->current(); if ( $current ) { $this->result->next(); - $result = new Result( $this->result, $current, $this->config ); + $result = new Result( $this->result, $current ); $this->augmentResult( $result ); return $result; } @@ -297,12 +289,5 @@ */ public function getQueryAfterRewriteSnippet() { return $this->rewrittenQuerySnippet; - } - - /** - * @return SearchConfig - */ - public function getConfig() { - return $this->config; } } diff --git a/includes/Search/ResultsType.php b/includes/Search/ResultsType.php index 534d117..d81a933 100644 --- a/includes/Search/ResultsType.php +++ b/includes/Search/ResultsType.php @@ -3,7 +3,6 @@ namespace CirrusSearch\Search; use CirrusSearch\Searcher; -use CirrusSearch\SearchConfig; use MediaWiki\Logger\LoggerFactory; use Title; @@ -66,24 +65,6 @@ abstract class BaseResultsType implements ResultsType { use TitleHelper; - /** @var SearchConfig */ - private $config; - - /** - * @param SearchConfig $config - */ - public function __construct( SearchConfig $config ) { - $this->config = $config; - } - - /** - * TODO: remove when getWikiCode is removed - * @return SearchConfig - */ - public function getConfig() { - return $this->config; - } - /** * @return false|string|array corresponding to Elasticsearch source filtering syntax */ @@ -142,11 +123,9 @@ * Build result type. The matchedAnalyzer is required to detect if the match * was from the title or a redirect (and is kind of a leaky abstraction.) * - * @param SearchConfig $config * @param string $matchedAnalyzer the analyzer used to match the title */ - public function __construct( SearchConfig $config, $matchedAnalyzer ) { - parent::_construct( $config ); + public function __construct( $matchedAnalyzer ) { $this->matchedAnalyzer = $matchedAnalyzer; } @@ -293,11 +272,9 @@ private $highlightingConfig; /** - * @param SearchConfig $config * @param int $highlightingConfig Bitmask, see HIGHLIGHT_* consts */ - public function __construct( SearchConfig $config, $highlightingConfig ) { - parent::__construct( $config ); + public function __construct( $highlightingConfig ) { $this->highlightingConfig = $highlightingConfig; } @@ -476,8 +453,7 @@ $context->getSuggestPrefixes(), $context->getSuggestSuffixes(), $result, - $context->isSyntaxUsed(), - $this->getConfig() + $context->isSyntaxUsed() ); } @@ -612,8 +588,7 @@ $context->getSuggestPrefixes(), $context->getSuggestSuffixes(), $result, - $context->isSyntaxUsed(), - $this->getConfig() + $context->isSyntaxUsed() ); } diff --git a/includes/Search/TitleHelper.php b/includes/Search/TitleHelper.php index 43e9c54..1764cbb 100644 --- a/includes/Search/TitleHelper.php +++ b/includes/Search/TitleHelper.php @@ -77,8 +77,8 @@ if ( isset ( $r->wiki ) && $r->wiki !== wfWikiID() ) { return true; } - // TODO: replace by return false when wiki is populated - return !empty( $this->getConfig()->getWikiCode() ); + // no wiki is suspicious, should we log a warning? + return false; } /** @@ -91,8 +91,8 @@ ->getService( InterwikiResolver::SERVICE ) ->getInterwikiPrefix( $r->wiki ); } - // TODO: replace by return false when wiki is populated - return $this->getConfig()->getWikiCode(); + // no wiki is suspicious, should we log somthing? + return null; } /** @@ -117,10 +117,4 @@ $lb->execute(); } } - - /** - * TODO: remove when getWikiCode is removed - * @return SearchConfig - */ - public abstract function getConfig(); } diff --git a/includes/SearchConfig.php b/includes/SearchConfig.php index 41c4339..aab0c39 100644 --- a/includes/SearchConfig.php +++ b/includes/SearchConfig.php @@ -67,17 +67,14 @@ * setting to false will only set the wikiId to $overrideName but will * keep the current wiki config. This should be removed and no longer * when all the wikis have the wiki field populated. - * TODO: remove $fullLoad */ - public function __construct( $overrideName = null, $fullLoad = true ) { + public function __construct( $overrideName = null ) { if ( $overrideName && $overrideName != wfWikiID() ) { $this->wikiId = $overrideName; - if ( $fullLoad ) { - $this->source = new \HashConfig( $this->getConfigVars( $overrideName, self::CIRRUS_VAR_PREFIX ) ); - $this->prefix = 'wg'; - // Re-create language object - $this->source->set( 'wgContLang', \Language::factory( $this->source->get( 'wgLanguageCode' ) ) ); - } + $this->source = new \HashConfig( $this->getConfigVars( $overrideName, self::CIRRUS_VAR_PREFIX ) ); + $this->prefix = 'wg'; + // Re-create language object + $this->source->set( 'wgContLang', \Language::factory( $this->source->get( 'wgLanguageCode' ) ) ); return; } $this->source = new \GlobalVarConfig(); @@ -349,36 +346,5 @@ return true; } return false; - } - - /** - * Build a new SearchConfig based on $wiki - * TODO: remove $fullLoad - * @param $wiki dbname of the target wiki - * @return SearchConfig - */ - public function newInterwikiConfig( $wiki, $fullLoad = true ) { - if ( $wiki === $this->wikiId ) { - return $this; - } - - return new self( $wiki, $fullLoad ); - } - - /** - * Should not be needed when all wikis have the wiki field - * populated - * TODO: remove the interwiki prefix should not be stored here - * but infered from the wiki field. - * @deprecated - * @return string interwiki prefix - */ - public function getWikiCode() { - if ( $this->wikiId != wfWikiID() ) { - return \MediaWiki\MediaWikiServices::getInstance() - ->getService( InterwikiResolver::SERVICE ) - ->getInterwikiPrefix( $this->wikiId ); - } - return ''; } } diff --git a/tests/unit/Search/ResultTest.php b/tests/unit/Search/ResultTest.php index 338b810..2fb6efe 100644 --- a/tests/unit/Search/ResultTest.php +++ b/tests/unit/Search/ResultTest.php @@ -26,6 +26,7 @@ 'namespace' => NS_MAIN, 'namespace_text' => '', 'title' => 'Main Page', + 'wiki' => 'eswiki', 'redirect' => [ [ 'title' => 'Main', @@ -38,22 +39,6 @@ 'heading' => [ '...' ], ], ]; - $elasticaResult = new \Elastica\Result( $data ); - // Test BC Code, interwiki info is obtained - // by SearchConfig::getWikiCode() - $result = new Result( - $elasticaResultSet, - $elasticaResult, - $config->newInterwikiConfig( 'eswiki', false ) - ); - - $this->assertTrue( $result->getTitle()->isExternal(), 'isExternal BC mode' ); - $this->assertTrue( $result->getRedirectTitle()->isExternal(), 'redirect isExternal BC mode' ); - $this->assertTrue( $result->getSectionTitle()->isExternal(), 'section title isExternal BC mode' ); - - // Should be the default mode soon interwiki is detected by - // reading the wiki source field - $data['_source']['wiki'] = 'eswiki'; $elasticaResult = new \Elastica\Result( $data ); $result = new Result( $elasticaResultSet, diff --git a/tests/unit/Search/ResultsTypeTest.php b/tests/unit/Search/ResultsTypeTest.php index 49d5ef0..4056230 100644 --- a/tests/unit/Search/ResultsTypeTest.php +++ b/tests/unit/Search/ResultsTypeTest.php @@ -33,10 +33,7 @@ array $expected ) { $this->setMwGlobals( 'wgCirrusSearchUseExperimentalHighlighter', $useExperimentalHighlighter ); - $config = \MediaWiki\MediawikiServices::getInstance() - ->getConfigFactory() - ->makeConfig( 'CirrusSearch' ); - $type = new FullTextResultsType( $config, $highlightingConfig ); + $type = new FullTextResultsType( $highlightingConfig ); $this->assertEquals( $expected, $type->getHighlightingConfiguration( $highlightSource ) ); } -- To view, visit https://gerrit.wikimedia.org/r/320788 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9070e311ab1906038196dfda45ca1750cdceb9d0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: DCausse <dcau...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits