33 parent::__construct( $query, $moduleName,
'ps' );
41 $this->
run( $resultPageSet );
47 private function run( $resultPageSet =
null ) {
49 $search = $params[
'search'];
50 $limit = $params[
'limit'];
51 $offset = $params[
'offset'];
54 $suggestions = $searchEngine->completionSearchWithVariants( $search );
55 $titles = $searchEngine->extractTitles( $suggestions );
57 if ( $suggestions->hasMoreResults() ) {
61 if ( $resultPageSet ) {
62 $resultPageSet->setRedirectMergePolicy(
function ( array $current, array $new ) {
63 if ( !isset( $current[
'index'] ) || $new[
'index'] < $current[
'index'] ) {
64 $current[
'index'] = $new[
'index'];
68 $resultPageSet->populateFromTitles( $titles );
69 foreach ( $titles as $index =>
$title ) {
70 $resultPageSet->setGeneratorData(
$title, [
'index' => $index + $offset + 1 ] );
75 foreach ( $titles as
$title ) {
77 'ns' => (int)
$title->getNamespace(),
78 'title' =>
$title->getPrefixedText(),
80 if (
$title->isSpecialPage() ) {
81 $vals[
'special'] =
true;
83 $vals[
'pageid'] = (int)
$title->getArticleID();
85 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
92 $result->addIndexedTagName(
103 if ( $this->allowedParams !==
null ) {
114 'profile-type' => SearchEngine::COMPLETION_PROFILE_TYPE,
115 'help-message' =>
'apihelp-query+prefixsearch-param-profile',
122 'action=query&list=prefixsearch&pssearch=meaning'
123 =>
'apihelp-query+prefixsearch-example-simple',
128 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.
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.
__construct( $query, $moduleName)
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.
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
getExamplesMessages()
Returns usage examples for this module.
trait SearchApi
Traits for API components that use a SearchEngine.