44 parent::__construct( $query, $moduleName,
'ps' );
46 $this->searchEngineConfig = $searchEngineConfig;
55 $this->
run( $resultPageSet );
61 private function run( $resultPageSet =
null ) {
63 $search = $params[
'search'];
64 $limit = $params[
'limit'];
65 $offset = $params[
'offset'];
68 $suggestions = $searchEngine->completionSearchWithVariants( $search );
69 $titles = $searchEngine->extractTitles( $suggestions );
71 if ( $suggestions->hasMoreResults() ) {
75 if ( $resultPageSet ) {
76 $resultPageSet->setRedirectMergePolicy(
static function ( array $current, array $new ) {
77 if ( !isset( $current[
'index'] ) || $new[
'index'] < $current[
'index'] ) {
78 $current[
'index'] = $new[
'index'];
82 $resultPageSet->populateFromTitles( $titles );
83 foreach ( $titles as $index =>
$title ) {
84 $resultPageSet->setGeneratorData(
$title, [
'index' => $index + $offset + 1 ] );
89 foreach ( $titles as
$title ) {
91 'ns' =>
$title->getNamespace(),
92 'title' =>
$title->getPrefixedText(),
94 if (
$title->isSpecialPage() ) {
95 $vals[
'special'] =
true;
97 $vals[
'pageid'] = (int)
$title->getArticleID();
99 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
106 $result->addIndexedTagName(
117 if ( $this->allowedParams !==
null ) {
128 'profile-type' => SearchEngine::COMPLETION_PROFILE_TYPE,
129 'help-message' =>
'apihelp-query+prefixsearch-param-profile',
136 'action=query&list=prefixsearch&pssearch=meaning'
137 =>
'apihelp-query+prefixsearch-example-simple',
142 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Prefixsearch';
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.
SearchEngineFactory null $searchEngineFactory
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
array $allowedParams
list of api allowed params
getHelpUrls()
Return links to more detailed help pages about the module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName, SearchEngineConfig $searchEngineConfig, SearchEngineFactory $searchEngineFactory)
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Configuration handling class for SearchEngine.
Factory class for SearchEngine.
trait SearchApi
Traits for API components that use a SearchEngine.