MediaWiki master
MediaWiki\Search\SearchSuggestionSet Class Reference

A set of search suggestions. More...

Public Member Functions

 __construct (array $suggestions, $hasMoreResults=false)
 Builds a new set of suggestions.
 
 append (SearchSuggestion $suggestion)
 Add a new suggestion at the end.
 
 appendAll (SearchSuggestionSet $set)
 Add suggestion set to the end of the current one.
 
 filter ( $callback)
 Filter the suggestions array.
 
 getBestScore ()
 
 getSize ()
 
 getSuggestions ()
 Get the list of suggestions.
 
 getWorstScore ()
 
 hasMoreResults ()
 
 map ( $callback)
 Call array_map on the suggestions array.
 
 prepend (SearchSuggestion $suggestion)
 Add a new suggestion at the top.
 
 remove (SearchSuggestion $suggestion)
 Remove a suggestion from the set.
 
 rescore ( $key)
 Move the suggestion at index $key to the first position.
 
 shrink ( $limit)
 Remove any extra elements in the suggestions set.
 

Static Public Member Functions

static emptySuggestionSet ()
 
static fromStrings (array $titles, $hasMoreResults=false)
 Builds a new set of suggestion based on a string array.
 
static fromTitles (array $titles, $hasMoreResults=false)
 Builds a new set of suggestion based on a title array.
 

Detailed Description

A set of search suggestions.

The set is always ordered by score, with the best match first.

Definition at line 17 of file SearchSuggestionSet.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Search\SearchSuggestionSet::__construct ( array $suggestions,
$hasMoreResults = false )

Builds a new set of suggestions.

NOTE: the array should be sorted by score (higher is better), in descending order. SearchSuggestionSet will not try to re-order this input array. Providing an unsorted input array is a mistake and will lead to unexpected behaviors.

Parameters
SearchSuggestion[]$suggestions(must be sorted by score)
bool$hasMoreResultsAre more results available?

Definition at line 45 of file SearchSuggestionSet.php.

References MediaWiki\Search\SearchSuggestionSet\hasMoreResults().

Member Function Documentation

◆ append()

MediaWiki\Search\SearchSuggestionSet::append ( SearchSuggestion $suggestion)

Add a new suggestion at the end.

If the score of the new suggestion is greater than the worst one, the new suggestion score will be updated (worst - 1).

Definition at line 97 of file SearchSuggestionSet.php.

References MediaWiki\Search\SearchSuggestion\getScore(), MediaWiki\Search\SearchSuggestionSet\getSize(), MediaWiki\Search\SearchSuggestion\getSuggestedTitleID(), MediaWiki\Search\SearchSuggestionSet\getWorstScore(), and MediaWiki\Search\SearchSuggestion\setScore().

Referenced by MediaWiki\Search\SearchSuggestionSet\appendAll().

◆ appendAll()

MediaWiki\Search\SearchSuggestionSet::appendAll ( SearchSuggestionSet $set)

Add suggestion set to the end of the current one.

Definition at line 114 of file SearchSuggestionSet.php.

References MediaWiki\Search\SearchSuggestionSet\append(), and MediaWiki\Search\SearchSuggestionSet\getSuggestions().

◆ emptySuggestionSet()

static MediaWiki\Search\SearchSuggestionSet::emptySuggestionSet ( )
static
Returns
SearchSuggestionSet an empty suggestion set

Definition at line 262 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\completionSearch(), and MediaWiki\Search\SearchEngine\completionSearchWithVariants().

◆ filter()

MediaWiki\Search\SearchSuggestionSet::filter ( $callback)

Filter the suggestions array.

Parameters
callable$callbackCallable accepting single SearchSuggestion instance returning bool false to remove the item.
Returns
int The number of suggestions removed

Definition at line 86 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\processCompletionResults().

◆ fromStrings()

static MediaWiki\Search\SearchSuggestionSet::fromStrings ( array $titles,
$hasMoreResults = false )
static

Builds a new set of suggestion based on a string array.

NOTE: Suggestion scores will be generated.

Parameters
string[]$titles
bool$hasMoreResultsAre more results available?
Returns
SearchSuggestionSet

Definition at line 251 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\completionSearchBackend().

◆ fromTitles()

static MediaWiki\Search\SearchSuggestionSet::fromTitles ( array $titles,
$hasMoreResults = false )
static

Builds a new set of suggestion based on a title array.

Useful when using a backend that supports only Titles.

NOTE: Suggestion scores will be generated.

Parameters
Title[]$titles
bool$hasMoreResultsAre more results available?
Returns
SearchSuggestionSet

Definition at line 234 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\completionSearchBackend().

◆ getBestScore()

MediaWiki\Search\SearchSuggestionSet::getBestScore ( )
Returns
float the best score in this suggestion set

Definition at line 171 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchSuggestionSet\prepend().

◆ getSize()

MediaWiki\Search\SearchSuggestionSet::getSize ( )
Returns
int the number of suggestion in this set

Definition at line 191 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchSuggestionSet\append(), and MediaWiki\Search\SearchSuggestionSet\prepend().

◆ getSuggestions()

MediaWiki\Search\SearchSuggestionSet::getSuggestions ( )

Get the list of suggestions.

Returns
SearchSuggestion[]

Definition at line 67 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchSuggestionSet\appendAll().

◆ getWorstScore()

MediaWiki\Search\SearchSuggestionSet::getWorstScore ( )
Returns
float the worst score in this set

Definition at line 181 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchSuggestionSet\append().

◆ hasMoreResults()

MediaWiki\Search\SearchSuggestionSet::hasMoreResults ( )
Returns
bool Are more results available?

Definition at line 59 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchSuggestionSet\__construct().

◆ map()

MediaWiki\Search\SearchSuggestionSet::map ( $callback)

Call array_map on the suggestions array.

Parameters
callable$callback
Returns
array

Definition at line 76 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\extractTitles(), and MediaWiki\Search\SearchEngine\processCompletionResults().

◆ prepend()

MediaWiki\Search\SearchSuggestionSet::prepend ( SearchSuggestion $suggestion)

◆ remove()

MediaWiki\Search\SearchSuggestionSet::remove ( SearchSuggestion $suggestion)

Remove a suggestion from the set.

Removes the first suggestion that has the same article id or the same suggestion text.

Parameters
SearchSuggestion$suggestion
Returns
bool true if something was removed

Definition at line 154 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\processCompletionResults().

◆ rescore()

MediaWiki\Search\SearchSuggestionSet::rescore ( $key)

Move the suggestion at index $key to the first position.

Parameters
int$key

Definition at line 124 of file SearchSuggestionSet.php.

References MediaWiki\Search\SearchSuggestionSet\prepend().

Referenced by MediaWiki\Search\SearchEngine\processCompletionResults().

◆ shrink()

MediaWiki\Search\SearchSuggestionSet::shrink ( $limit)

Remove any extra elements in the suggestions set.

Parameters
int$limitthe max size of this set.

Definition at line 199 of file SearchSuggestionSet.php.

Referenced by MediaWiki\Search\SearchEngine\processCompletionResults().


The documentation for this class was generated from the following file: