57 foreach ( $suggestions as $suggestion ) {
58 $pageID = $suggestion->getSuggestedTitleID();
59 if ( $pageID && empty( $this->pageMap[$pageID] ) ) {
60 $this->pageMap[$pageID] =
true;
62 $this->suggestions[] = $suggestion;
86 public function map( $callback ) {
87 return array_map( $callback, $this->suggestions );
96 public function filter( $callback ) {
97 $before = count( $this->suggestions );
98 $this->suggestions = array_values( array_filter( $this->suggestions, $callback ) );
99 return $before - count( $this->suggestions );
111 if ( $pageID && isset( $this->pageMap[$pageID] ) ) {
114 if ( $this->
getSize() > 0 && $suggestion->
getScore() >= $this->getWorstScore() ) {
117 $this->suggestions[] = $suggestion;
119 $this->pageMap[$pageID] =
true;
138 $removed = array_splice( $this->suggestions, $key, 1 );
139 unset( $this->pageMap[$removed[0]->getSuggestedTitleID()] );
150 if ( $pageID && isset( $this->pageMap[$pageID] ) ) {
153 if ( $this->
getSize() > 0 && $suggestion->
getScore() <= $this->getBestScore() ) {
156 array_unshift( $this->suggestions, $suggestion );
158 $this->pageMap[$pageID] =
true;
166 if ( empty( $this->suggestions ) ) {
169 return $this->suggestions[0]->getScore();
176 if ( empty( $this->suggestions ) ) {
179 return end( $this->suggestions )->getScore();
186 return count( $this->suggestions );
194 if ( count( $this->suggestions ) > $limit ) {
195 $this->suggestions = array_slice( $this->suggestions, 0, $limit );
211 $score = count( $titles );
228 $score = count( $titles );
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?
static fromText( $score, $text)
Create suggestion from text Will also create a title if text if not empty.
getSuggestedTitleID()
Title ID in the case this suggestion is based on a title.
setScore( $score)
Set the suggestion score.
getScore()
Suggestion score.
static fromTitle( $score, Title $title)
Create suggestion from Title.