X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQuerySearch.php;h=80798a10cd7c0d0ce2d4fabd32ef62bafa4f1268;hb=31680aaddc8ddde150aa5ab2370a019a550f259d;hp=3955cc5f67a629b870fc84a0b24c2cb74dabcb9f;hpb=0af7afc9d3f7e82078c5d372473689e2ed7e7d27;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 3955cc5f67..80798a10cd 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -24,12 +24,18 @@ * @file */ +use MediaWiki\MediaWikiServices; + /** * Query module to perform full text search within wiki titles and content * * @ingroup API */ class ApiQuerySearch extends ApiQueryGeneratorBase { + use SearchApi; + + /** @var array list of api allowed params */ + private $allowedParams; /** * When $wgSearchType is null, $wgSearchAlternatives[0] is null. Null isn't @@ -59,8 +65,11 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { global $wgContLang; $params = $this->extractRequestParams(); + if ( isset( $params['backend'] ) && $params['backend'] == self::BACKEND_NULL_PARAM ) { + unset( $params['backend'] ); + } + // Extract parameters - $limit = $params['limit']; $query = $params['search']; $what = $params['what']; $interwiki = $params['interwiki']; @@ -78,10 +87,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } // Create search engine instance and set options - $search = isset( $params['backend'] ) && $params['backend'] != self::BACKEND_NULL_PARAM ? - SearchEngine::create( $params['backend'] ) : SearchEngine::create(); - $search->setLimitOffset( $limit + 1, $params['offset'] ); - $search->setNamespaces( $params['namespace'] ); + $search = $this->buildSearchEngine( $params ); $search->setFeatureData( 'rewrite', (bool)$params['enablerewrites'] ); $query = $search->transformSearchTerm( $query ); @@ -95,7 +101,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } elseif ( $what == 'nearmatch' ) { // near matches must receive the user input as provided, otherwise // the near matches within namespaces are lost. - $matches = SearchEngine::getNearMatchResultSet( $params['search'] ); + $matches = $search->getNearMatcher( $this->getConfig() ) + ->getNearMatchResultSet( $params['search'] ); } else { // We default to title searches; this is a terrible legacy // of the way we initially set up the MySQL fulltext-based @@ -148,6 +155,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $titles = []; $count = 0; $result = $matches->next(); + $limit = $params['limit']; while ( $result ) { if ( ++$count > $limit ) { @@ -297,7 +305,11 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } public function getAllowedParams() { - $params = [ + if ( $this->allowedParams !== null ) { + return $this->allowedParams; + } + + $this->allowedParams = [ 'search' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true @@ -358,18 +370,37 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { 'enablerewrites' => false, ]; - $alternatives = SearchEngine::getSearchTypes(); + $searchConfig = MediaWikiServices::getInstance()->getSearchEngineConfig(); + $alternatives = $searchConfig->getSearchTypes(); if ( count( $alternatives ) > 1 ) { if ( $alternatives[0] === null ) { $alternatives[0] = self::BACKEND_NULL_PARAM; } - $params['backend'] = [ - ApiBase::PARAM_DFLT => $this->getConfig()->get( 'SearchType' ), + $this->allowedParams['backend'] = [ + ApiBase::PARAM_DFLT => $searchConfig->getSearchType(), ApiBase::PARAM_TYPE => $alternatives, ]; + // @todo: support profile selection when multiple + // backends are available. The solution could be to + // merge all possible profiles and let ApiBase + // subclasses do the check. Making ApiHelp and ApiSandbox + // comprehensive might be more difficult. + } else { + $profileParam = $this->buildProfileApiParam( SearchEngine::FT_QUERY_INDEP_PROFILE_TYPE, + 'apihelp-query+search-param-qiprofile' ); + if ( $profileParam ) { + $this->allowedParams['qiprofile'] = $profileParam; + } } - return $params; + return $this->allowedParams; + } + + public function getSearchProfileParams() { + if ( isset( $this->getAllowedParams()['qiprofile'] ) ) { + return [ SearchEngine::FT_QUERY_INDEP_PROFILE_TYPE => 'qiprofile' ]; + } + return []; } protected function getExamplesMessages() {