35 private function checkDependenciesSet() {
41 if ( !isset( $this->searchEngineConfig ) || !isset( $this->searchEngineFactory ) ) {
42 throw new LogicException(
43 'SearchApi requires both a SearchEngineConfig and SearchEngineFactory to be set'
54 private static $BACKEND_NULL_PARAM =
'database-backed';
65 $this->checkDependenciesSet();
69 ParamValidator::PARAM_TYPE =>
'string',
70 ParamValidator::PARAM_REQUIRED =>
true,
73 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
74 ParamValidator::PARAM_TYPE =>
'namespace',
75 ParamValidator::PARAM_ISMULTI =>
true,
78 ParamValidator::PARAM_DEFAULT => 10,
79 ParamValidator::PARAM_TYPE =>
'limit',
80 IntegerDef::PARAM_MIN => 1,
85 if ( $isScrollable ) {
87 ParamValidator::PARAM_DEFAULT => 0,
88 IntegerDef::PARAM_MIN => 0,
89 ParamValidator::PARAM_TYPE =>
'integer',
94 $alternatives = $this->searchEngineConfig->getSearchTypes();
95 if ( count( $alternatives ) > 1 ) {
96 $alternatives[0] ??= self::$BACKEND_NULL_PARAM;
97 $params[
'backend'] = [
98 ParamValidator::PARAM_DEFAULT => $this->searchEngineConfig->getSearchType(),
99 ParamValidator::PARAM_TYPE => $alternatives,
107 $params += $this->buildProfileApiParam();
121 private function buildProfileApiParam() {
122 $this->checkDependenciesSet();
125 $searchEngine = $this->searchEngineFactory->create();
127 foreach ( $configs as $paramName => $paramConfig ) {
128 $profiles = $searchEngine->getProfiles(
129 $paramConfig[
'profile-type'],
138 $defaultProfile =
null;
139 foreach ( $profiles as $profile ) {
140 $types[] = $profile[
'name'];
141 if ( isset( $profile[
'desc-message'] ) ) {
142 $helpMessages[$profile[
'name']] = $profile[
'desc-message'];
145 if ( !empty( $profile[
'default'] ) ) {
146 $defaultProfile = $profile[
'name'];
150 $params[$paramName] = [
151 ParamValidator::PARAM_TYPE => $types,
154 ParamValidator::PARAM_DEFAULT => $defaultProfile,
175 $this->checkDependenciesSet();
177 if ( $params ==
null ) {
178 return $this->searchEngineFactory->create();
181 $type = $params[
'backend'] ??
null;
182 if ( $type === self::$BACKEND_NULL_PARAM ) {
185 $searchEngine = $this->searchEngineFactory->create( $type );
186 $searchEngine->setNamespaces( $params[
'namespace'] );
187 $searchEngine->setLimitOffset( $params[
'limit'], $params[
'offset'] ?? 0 );
191 foreach ( $configs as $paramName => $paramConfig ) {
192 if ( isset( $params[$paramName] ) ) {
193 $searchEngine->setFeatureData(
194 $paramConfig[
'profile-type'],
199 return $searchEngine;
buildSearchEngine(array $params=null)
Build the search engine to use.
buildCommonApiParams( $isScrollable=true)
The set of api parameters that are shared between api calls that call the SearchEngine.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
Configuration handling class for SearchEngine.
Factory class for SearchEngine.
trait SearchApi
Traits for API components that use a SearchEngine.