42 private function checkDependenciesSet() {
48 if ( !isset( $this->searchEngineConfig ) || !isset( $this->searchEngineFactory ) ) {
49 throw new LogicException(
50 'SearchApi requires both a SearchEngineConfig and SearchEngineFactory to be set'
62 private static $BACKEND_NULL_PARAM =
'database-backed';
73 $this->checkDependenciesSet();
77 ParamValidator::PARAM_TYPE =>
'string',
78 ParamValidator::PARAM_REQUIRED =>
true,
81 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
82 ParamValidator::PARAM_TYPE =>
'namespace',
83 ParamValidator::PARAM_ISMULTI =>
true,
86 ParamValidator::PARAM_DEFAULT => 10,
87 ParamValidator::PARAM_TYPE =>
'limit',
88 IntegerDef::PARAM_MIN => 1,
93 if ( $isScrollable ) {
95 ParamValidator::PARAM_DEFAULT => 0,
96 IntegerDef::PARAM_MIN => 0,
97 ParamValidator::PARAM_TYPE =>
'integer',
102 $alternatives = $this->searchEngineConfig->getSearchTypes();
103 if ( count( $alternatives ) > 1 ) {
104 $alternatives[0] ??= self::$BACKEND_NULL_PARAM;
106 ParamValidator::PARAM_DEFAULT => $this->searchEngineConfig->getSearchType(),
107 ParamValidator::PARAM_TYPE => $alternatives,
115 $params += $this->buildProfileApiParam();
129 private function buildProfileApiParam() {
130 $this->checkDependenciesSet();
133 $searchEngine = $this->searchEngineFactory->create();
135 foreach ( $configs as $paramName => $paramConfig ) {
136 $profiles = $searchEngine->getProfiles(
137 $paramConfig[
'profile-type'],
146 $defaultProfile =
null;
147 foreach ( $profiles as $profile ) {
148 $types[] = $profile[
'name'];
149 if ( isset( $profile[
'desc-message'] ) ) {
150 $helpMessages[$profile[
'name']] = $profile[
'desc-message'];
153 if ( !empty( $profile[
'default'] ) ) {
154 $defaultProfile = $profile[
'name'];
159 ParamValidator::PARAM_TYPE => $types,
162 ParamValidator::PARAM_DEFAULT => $defaultProfile,
183 $this->checkDependenciesSet();
186 return $this->searchEngineFactory->create();
189 $type =
$params[
'backend'] ??
null;
190 if ( $type === self::$BACKEND_NULL_PARAM ) {
193 $searchEngine = $this->searchEngineFactory->create( $type );
194 $searchEngine->setNamespaces(
$params[
'namespace'] );
195 $searchEngine->setLimitOffset(
$params[
'limit'],
$params[
'offset'] ?? 0 );
199 foreach ( $configs as $paramName => $paramConfig ) {
200 if ( isset(
$params[$paramName] ) ) {
201 $searchEngine->setFeatureData(
202 $paramConfig[
'profile-type'],
207 return $searchEngine;
223class_alias( SearchApi::class,
'SearchApi' );
array $params
The job parameters.
Configuration handling class for SearchEngine.
Factory class for SearchEngine.
Contain a class for special pages.
trait SearchApi
Traits for API components that use a SearchEngine.
Interface for objects which can provide a MediaWiki context on request.