MediaWiki REL1_28
SearchSuggestionSet Class Reference

Search suggestion sets. More...

Collaboration diagram for SearchSuggestionSet:

Public Member Functions

 __construct (array $suggestions)
 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.
 
 getBestScore ()
 
 getSize ()
 
 getSuggestions ()
 Get the list of suggestions.
 
 getWorstScore ()
 
 map ( $callback)
 Call array_map on the suggestions array.
 
 prepend (SearchSuggestion $suggestion)
 Add a new suggestion at the top.
 
 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)
 Builds a new set of suggestion based on a string array.
 
static fromTitles (array $titles)
 Builds a new set of suggestion based on a title array.
 

Private Attributes

array $pageMap = []
 
SearchSuggestion[] $suggestions = []
 

Detailed Description

Search suggestion sets.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html A set of search suggestions. The set is always ordered by score, with the best match first.

Definition at line 27 of file SearchSuggestionSet.php.

Constructor & Destructor Documentation

◆ __construct()

SearchSuggestionSet::__construct ( array  $suggestions)

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)

Definition at line 50 of file SearchSuggestionSet.php.

References $suggestions, and as.

Member Function Documentation

◆ append()

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).

Parameters
SearchSuggestion$suggestion

Definition at line 84 of file SearchSuggestionSet.php.

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

Referenced by appendAll().

◆ appendAll()

SearchSuggestionSet::appendAll ( SearchSuggestionSet  $set)

Add suggestion set to the end of the current one.

Parameters
SearchSuggestionSet$set

Definition at line 102 of file SearchSuggestionSet.php.

References append(), as, and getSuggestions().

◆ emptySuggestionSet()

◆ fromStrings()

static SearchSuggestionSet::fromStrings ( array  $titles)
static

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

NOTE: Suggestion scores will be generated.

Parameters
string[]$titles
Returns
SearchSuggestionSet

Definition at line 198 of file SearchSuggestionSet.php.

References $suggestions, $title, $titles, SearchSuggestion\fromText(), and use.

Referenced by SearchEngine\completionSearchBackend(), and SearchEnginePrefixTest\testSearchBackend().

◆ fromTitles()

static SearchSuggestionSet::fromTitles ( array  $titles)
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
Returns
SearchSuggestionSet

Definition at line 182 of file SearchSuggestionSet.php.

References $suggestions, $title, $titles, SearchSuggestion\fromTitle(), and use.

Referenced by SearchEngine\completionSearchBackend().

◆ getBestScore()

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

Definition at line 139 of file SearchSuggestionSet.php.

Referenced by prepend().

◆ getSize()

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

Definition at line 159 of file SearchSuggestionSet.php.

Referenced by append(), and prepend().

◆ getSuggestions()

SearchSuggestionSet::getSuggestions ( )

Get the list of suggestions.

Returns
SearchSuggestion[]

Definition at line 64 of file SearchSuggestionSet.php.

References $suggestions.

Referenced by appendAll().

◆ getWorstScore()

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

Definition at line 149 of file SearchSuggestionSet.php.

Referenced by append().

◆ map()

SearchSuggestionSet::map (   $callback)

Call array_map on the suggestions array.

Parameters
callback$callback
Returns
array

Definition at line 73 of file SearchSuggestionSet.php.

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

◆ prepend()

SearchSuggestionSet::prepend ( SearchSuggestion  $suggestion)

Add a new suggestion at the top.

If the new suggestion score is lower than the best one its score will be updated (best + 1)

Parameters
SearchSuggestion$suggestion

Definition at line 122 of file SearchSuggestionSet.php.

References getBestScore(), SearchSuggestion\getScore(), getSize(), SearchSuggestion\getSuggestedTitleID(), and SearchSuggestion\setScore().

Referenced by SearchEngine\processCompletionResults(), and rescore().

◆ rescore()

SearchSuggestionSet::rescore (   $key)

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

Definition at line 111 of file SearchSuggestionSet.php.

References prepend().

Referenced by SearchEngine\processCompletionResults().

◆ shrink()

SearchSuggestionSet::shrink (   $limit)

Remove any extra elements in the suggestions set.

Parameters
int$limitthe max size of this set.

Definition at line 167 of file SearchSuggestionSet.php.

References $limit.

Referenced by SearchEngine\processCompletionResults().

Member Data Documentation

◆ $pageMap

array SearchSuggestionSet::$pageMap = []
private

Definition at line 37 of file SearchSuggestionSet.php.

◆ $suggestions

SearchSuggestion [] SearchSuggestionSet::$suggestions = []
private

Definition at line 31 of file SearchSuggestionSet.php.

Referenced by __construct(), fromStrings(), fromTitles(), and getSuggestions().


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