56 foreach ( $suggestions as $suggestion ) {
57 $pageID = $suggestion->getSuggestedTitleID();
58 if ( $pageID && empty( $this->pageMap[$pageID] ) ) {
59 $this->pageMap[$pageID] =
true;
61 $this->suggestions[] = $suggestion;
85 public function map( $callback ) {
86 return array_map( $callback, $this->suggestions );
95 public function filter( $callback ) {
96 $before = count( $this->suggestions );
97 $this->suggestions = array_values( array_filter( $this->suggestions, $callback ) );
98 return $before - count( $this->suggestions );
110 if ( $pageID && isset( $this->pageMap[$pageID] ) ) {
113 if ( $this->
getSize() > 0 && $suggestion->
getScore() >= $this->getWorstScore() ) {
116 $this->suggestions[] = $suggestion;
118 $this->pageMap[$pageID] =
true;
137 $removed = array_splice( $this->suggestions, $key, 1 );
138 unset( $this->pageMap[$removed[0]->getSuggestedTitleID()] );
149 if ( $pageID && isset( $this->pageMap[$pageID] ) ) {
152 if ( $this->
getSize() > 0 && $suggestion->
getScore() <= $this->getBestScore() ) {
155 array_unshift( $this->suggestions, $suggestion );
157 $this->pageMap[$pageID] =
true;
165 if ( empty( $this->suggestions ) ) {
168 return $this->suggestions[0]->getScore();
175 if ( empty( $this->suggestions ) ) {
178 return end( $this->suggestions )->getScore();
185 return count( $this->suggestions );
193 if ( count( $this->suggestions ) > $limit ) {
194 $this->suggestions = array_slice( $this->suggestions, 0, $limit );
210 $score = count( $titles );
212 return SearchSuggestion::fromTitle( $score--,
$title );
227 $score = count( $titles );
229 return SearchSuggestion::fromText( $score--,
$title );
append(SearchSuggestion $suggestion)
Add a new suggestion at the end.
filter( $callback)
Filter the suggestions array.
rescore( $key)
Move the suggestion at index $key to the first position.
shrink( $limit)
Remove any extra elements in the suggestions set.
static fromStrings(array $titles, $hasMoreResults=false)
Builds a new set of suggestion based on a string array.
appendAll(SearchSuggestionSet $set)
Add suggestion set to the end of the current one.
static fromTitles(array $titles, $hasMoreResults=false)
Builds a new set of suggestion based on a title array.
getSuggestions()
Get the list of suggestions.
static emptySuggestionSet()
map( $callback)
Call array_map on the suggestions array.
SearchSuggestion[] $suggestions
prepend(SearchSuggestion $suggestion)
Add a new suggestion at the top.
__construct(array $suggestions, $hasMoreResults=false)
Builds a new set of suggestions.
bool $hasMoreResults
Are more results available?
getSuggestedTitleID()
Title ID in the case this suggestion is based on a title.
setScore( $score)
Set the suggestion score.
getScore()
Suggestion score.