DCausse has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/401575 )
Change subject: [WIP] Integrate with cirrus profile service
......................................................................
[WIP] Integrate with cirrus profile service
Cirrus uses many verbose profiles that are cumbersome to carry
and manipulate. The profile service tries to unify the logic of profile
management. It allows extension to declare their own profiles without
dealing with cirrus internals (merging config arrays...).
By implementing the CirrusSearchProfileService hook wikibase can now
declare:
- some default profiles that will be available on all wikibase installs
- config vars that can be set by users to customize/tune the default profiles
Bug: T183279
Depends-On: Icca9a44373d26309ac4e1c2392cebecdf2fae46b
Change-Id: I458c3a18f4d1e0f3f3d8ab466053845745902751
---
M repo/Wikibase.hooks.php
M repo/Wikibase.php
M repo/config/Wikibase.default.php
M repo/includes/Search/Elastic/EntitySearchElastic.php
M repo/tests/phpunit/includes/Api/SearchEntitiesIntegrationTest.php
M repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
6 files changed, 46 insertions(+), 48 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/75/401575/1
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index d56e039..0e266ee 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -7,6 +7,7 @@
use ApiQuerySiteinfo;
use BaseTemplate;
use CirrusSearch\Maintenance\AnalysisConfigBuilder;
+use CirrusSearch\Profile\SearchProfileService;
use CirrusSearch\Search\FunctionScoreBuilder;
use CirrusSearch\Search\SearchContext;
use Content;
@@ -38,6 +39,7 @@
use Wikibase\Repo\Content\EntityHandler;
use Wikibase\Repo\Hooks\InfoActionHookHandler;
use Wikibase\Repo\Hooks\OutputPageEntityIdReader;
+use Wikibase\Repo\Search\Elastic\EntitySearchElastic;
use Wikibase\Repo\Search\Elastic\Fields\StatementsField;
use Wikibase\Repo\Search\Elastic\ConfigBuilder;
use Wikibase\Repo\Search\Elastic\StatementBoostScoreBuilder;
@@ -126,12 +128,7 @@
$settings->setSetting( 'entitySearch', $searchSettings
);
}
if ( $searchSettings['useCirrus'] ) {
- global $wgCirrusSearchRescoreFunctionScoreChains,
$wgCirrusSearchExtraIndexSettings;
- // ElasticSearch function for entity weight
- $wgCirrusSearchRescoreFunctionScoreChains = array_merge(
- isset(
$wgCirrusSearchRescoreFunctionScoreChains ) ?
$wgCirrusSearchRescoreFunctionScoreChains : [],
- require __DIR__ .
'/config/ElasticSearchRescoreFunctions.php'
- );
+ global $wgCirrusSearchExtraIndexSettings;
// Bump max fields so that labels/descriptions fields
fit in.
$wgCirrusSearchExtraIndexSettings['index.mapping.total_fields.limit'] = 5000;
@@ -1090,4 +1087,34 @@
}
}
+ /**
+ * Register our cirrus profiles.
+ *
+ * @param SearchProfileService $profileService
+ */
+ public static function onCirrusSearchProfileService(
SearchProfileService $profileService ) {
+ // register base profiles available on all wikibase installs
+ $profileService->registerArrayRepository(
SearchProfileService::RESCORE,
+ 'wikibase_base', require __DIR__ .
'/config/ElasticSearchRescoreProfiles.php' );
+ $profileService->registerArrayRepository(
SearchProfileService::RESCORE_FUNCTION_CHAINS,
+ 'wikibase_base', require __DIR__ .
'/config/ElasticSearchRescoreFunctions.php' );
+
+ // register custom profiles provided in the wikibase config
+ $settings = WikibaseRepo::getDefaultInstance()->getSettings();
+ $entitySearchConfig = $settings->getSetting( 'entitySearch' );
+ if ( isset( $entitySearchConfig['rescoreProfiles'] ) ) {
+ $profileService->registerArrayRepository(
SearchProfileService::RESCORE,
+ 'wikibase_config',
$entitySearchConfig['rescoreProfiles'] );
+ }
+
+ // Determine the default rescore profile to use for entity
autocomplete search
+ $defaultRescore = EntitySearchElastic::DEFAULT_RESCORE_PROFILE;
+ if ( isset( $entitySearchConfig['defaultPrefixRescoreProfile']
) ) {
+ $defaultRescore =
$entitySearchConfig['defaultPrefixRescoreProfile'];
+ }
+ // Setup the default rescore profile for the prefix search query
+ // with the possibility to override the profile by setting the
URI param cirrusRescoreProfile
+ $profileService->registerSimpleNameResolver(
SearchProfileService::RESCORE,
+ $defaultRescore, EntitySearchElastic::PROFILE_CONTEXT,
'cirrusRescoreProfile' );
+ }
}
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index d87bb096..6b65808 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -1014,6 +1014,7 @@
$wgHooks['BeforePageDisplayMobile'][] =
'\Wikibase\RepoHooks::onBeforePageDisplayMobile';
$wgHooks['CirrusSearchAnalysisConfig'][] =
'\Wikibase\RepoHooks::onCirrusSearchAnalysisConfig';
$wgHooks['CirrusSearchScoreBuilder'][] =
'\Wikibase\RepoHooks::onCirrusSearchScoreBuilder';
+ $wgHooks['CirrusSearchProfileService'][] =
'\Wikibase\RepoHooks::onCirrusSearchProfileService';
// update hooks
$wgHooks['LoadExtensionSchemaUpdates'][] =
'\Wikibase\Repo\Store\Sql\ChangesSubscriptionSchemaUpdater::onSchemaUpdate';
@@ -1034,11 +1035,4 @@
// vs. fallback language match.
$wgWBRepoSettings['entitySearch']['prefixSearchProfiles'] =
require __DIR__ . '/config/EntityPrefixSearchProfiles.php';
- // Wikibase prefix search scoring profile for CirrusSearch.
- // This profile applies to the whole document.
- // These configurations define how the results are ordered.
- // The names should be distinct from other Cirrus rescoring profile, so
- // prefixing with 'wikibase' is recommended.
- $wgWBRepoSettings['entitySearch']['rescoreProfiles'] =
- require __DIR__ . '/config/ElasticSearchRescoreProfiles.php';
} );
diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php
index c2f7c2d..25d1b28 100644
--- a/repo/config/Wikibase.default.php
+++ b/repo/config/Wikibase.default.php
@@ -253,7 +253,7 @@
'prefixSearchProfiles' => [],
// Default rescore profile for prefix search
'defaultPrefixRescoreProfile' => 'wikibase_prefix',
- // Rescore profiles, loaded by Wikibase.php
+ // Custom rescore profiles placeholder
'rescoreProfiles' => [],
// Type (de)boosts for rescoring functions
'statementBoost' => [],
diff --git a/repo/includes/Search/Elastic/EntitySearchElastic.php
b/repo/includes/Search/Elastic/EntitySearchElastic.php
index 5623bf8..59ae558 100644
--- a/repo/includes/Search/Elastic/EntitySearchElastic.php
+++ b/repo/includes/Search/Elastic/EntitySearchElastic.php
@@ -2,6 +2,7 @@
namespace Wikibase\Repo\Search\Elastic;
+use CirrusSearch\Profile\SearchProfileService;
use CirrusSearch\Search\SearchContext;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
@@ -30,6 +31,11 @@
* Default rescore profile
*/
const DEFAULT_RESCORE_PROFILE = 'wikibase_prefix';
+
+ /**
+ * Name of the context for profile name resolution
+ */
+ const PROFILE_CONTEXT = 'wikibase_prefix_search';
/**
* @var LanguageFallbackChainFactory
@@ -245,26 +251,6 @@
}
/**
- * Get suitable rescore profile.
- * If internal config has non, return just the name and let
RescoureBuilder handle it.
- * @return string|array
- */
- private function getRescoreProfile() {
-
- $rescoreProfile = $this->request->getVal(
'cirrusRescoreProfile' );
- if ( !$rescoreProfile && isset(
$this->settings['defaultPrefixRescoreProfile'] ) ) {
- $rescoreProfile =
$this->settings['defaultPrefixRescoreProfile'];
- }
- if ( !$rescoreProfile ) {
- $rescoreProfile = self::DEFAULT_RESCORE_PROFILE;
- }
- if ( isset( $this->settings['rescoreProfiles'][$rescoreProfile]
) ) {
- return
$this->settings['rescoreProfiles'][$rescoreProfile];
- }
- return $rescoreProfile;
- }
-
- /**
* Parse entity ID or return null
* @param $text
* @return null|\Wikibase\DataModel\Entity\EntityId
@@ -339,7 +325,10 @@
) );
$searcher->setOptionsFromRequest( $this->request );
- $searcher->setRescoreProfile( $this->getRescoreProfile() );
+ $searcher->setRescoreProfile( $searcher->getSearchContext()
+ ->getConfig()
+ ->getProfileService()
+ ->loadProfileForContext( SearchProfileService::RESCORE,
self::PROFILE_CONTEXT ) );
$result = $searcher->performSearch( $query );
diff --git a/repo/tests/phpunit/includes/Api/SearchEntitiesIntegrationTest.php
b/repo/tests/phpunit/includes/Api/SearchEntitiesIntegrationTest.php
index 155e9fe..8901b36 100644
--- a/repo/tests/phpunit/includes/Api/SearchEntitiesIntegrationTest.php
+++ b/repo/tests/phpunit/includes/Api/SearchEntitiesIntegrationTest.php
@@ -51,12 +51,6 @@
parent::setUp();
$this->idParser = new BasicEntityIdParser();
-
- // ElasticSearch function for entity weight
- $this->mergeMwGlobalArrayValue(
- 'wgCirrusSearchRescoreFunctionScoreChains',
- require __DIR__ .
'/../../../../config/ElasticSearchRescoreFunctions.php'
- );
}
public function provideQueriesForEntityIds() {
diff --git
a/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
b/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
index 6a3e16c..a9c6192 100644
--- a/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
+++ b/repo/tests/phpunit/includes/Search/Elastic/EntitySearchElasticTest.php
@@ -65,13 +65,7 @@
* @param string $expected
*/
public function testSearchElastic( $params, $expected ) {
- $this->setMwGlobals( [
- 'wgEntitySearchUseCirrus' => true,
- 'wgCirrusSearchRescoreProfiles' =>
- include __DIR__ .
'/../../../../../config/ElasticSearchRescoreProfiles.php',
- 'wgCirrusSearchRescoreFunctionScoreChains' =>
- include __DIR__ .
'/../../../../../config/ElasticSearchRescoreFunctions.php',
- ] );
+ $this->setMwGlobals( [ 'wgEntitySearchUseCirrus' => true ] );
$search = $this->newEntitySearch( Language::factory(
$params['userLang'] ) );
$search->setRequest( $this->getMockRequest() );
$search->setReturnResult( true );
--
To view, visit https://gerrit.wikimedia.org/r/401575
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I458c3a18f4d1e0f3f3d8ab466053845745902751
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits