MediaWiki  1.27.2
SearchEngine Class Reference

Contain a class for special pages. More...

Inheritance diagram for SearchEngine:
Collaboration diagram for SearchEngine:

Public Member Functions

 completionSearch ($search)
 Perform a completion search. More...
 
 completionSearchWithVariants ($search)
 Perform a completion search with variants. More...
 
 defaultPrefixSearch ($search)
 Simple prefix search for subpages. More...
 
 delete ($id, $title)
 Delete an indexed page Title should be pre-processed. More...
 
 extractTitles (SearchSuggestionSet $completionResults)
 Extract titles from completion results. More...
 
 getNearMatcher (Config $config)
 Get service class to finding near matches. More...
 
 getSort ()
 Get the sort direction of the search results. More...
 
 getTextFromContent (Title $t, Content $c=null)
 Get the raw text for updating the index from a content object Nicer search backends could possibly do something cooler than just returning raw text. More...
 
 getValidSorts ()
 Get the valid sort directions. More...
 
 normalizeText ($string)
 When overridden in derived class, performs database-specific conversions on text to be used for searching or updating search index. More...
 
 replacePrefixes ($query)
 Parse some common prefixes: all (search everything) or namespace names. More...
 
 searchText ($term)
 Perform a full text search query and return a result set. More...
 
 searchTitle ($term)
 Perform a title-only search query and return a result set. More...
 
 setFeatureData ($feature, $data)
 Way to pass custom data for engines. More...
 
 setLimitOffset ($limit, $offset=0)
 Set the maximum number of results to return and how many to skip before returning the first. More...
 
 setNamespaces ($namespaces)
 Set which namespaces the search should include. More...
 
 setShowSuggestion ($showSuggestion)
 Set whether the searcher should try to build a suggestion. More...
 
 setSort ($sort)
 Set the sort direction of the search results. More...
 
 supports ($feature)
 
 textAlreadyUpdatedForIndex ()
 If an implementation of SearchEngine handles all of its own text processing in getTextFromContent() and doesn't require SearchUpdate::updateText()'s rather silly handling, it should return true here instead. More...
 
 transformSearchTerm ($term)
 Transform search term in cases when parts of the query came as different GET params (when supported), e.g. More...
 
 update ($id, $title, $text)
 Create or update the search index record for the given page. More...
 
 updateTitle ($id, $title)
 Update a search index record's title only. More...
 

Static Public Member Functions

static create ($type=null)
 Load up the appropriate search engine class for the currently active database backend, and return a configured instance. More...
 
static defaultNamespaces ()
 An array of namespaces indexes to be searched by default. More...
 
static getNearMatch ($searchterm)
 If an exact title match can be found, or a very slightly close match, return the title. More...
 
static getNearMatchResultSet ($searchterm)
 Do a near match (see SearchEngine::getNearMatch) and wrap it into a SearchResultSet. More...
 
static getOpenSearchTemplate ()
 Get OpenSearch suggestion template. More...
 
static getSearchTypes ()
 Return the search engines we support. More...
 
static legalSearchChars ()
 Get chars legal for search. More...
 
static namespacesAsText ($namespaces)
 Get a list of namespace names useful for showing in tooltips and preferences. More...
 
static searchableNamespaces ()
 Make a list of searchable namespaces and their canonical names. More...
 
static userHighlightPrefs ()
 Find snippet highlight settings for all users. More...
 
static userNamespaces ($user)
 Extract default namespaces to search from the given user's settings, returning a list of index numbers. More...
 

Public Attributes

int[] null $namespaces = [ NS_MAIN ]
 
string $prefix = ''
 

Protected Member Functions

 completionSearchBackend ($search)
 Perform a completion search. More...
 
 normalizeNamespaces ($search)
 Makes search simple string if it was namespaced. More...
 
 processCompletionResults ($search, SearchSuggestionSet $suggestions)
 Process completion search results. More...
 
 simplePrefixSearch ($search)
 Call out to simple search backend. More...
 

Static Protected Member Functions

static defaultNearMatcher ()
 Get near matcher for default SearchEngine. More...
 

Protected Attributes

array $features = []
 Feature values. More...
 
int $limit = 10
 
int $offset = 0
 
array string $searchTerms = []
 
bool $showSuggestion = true
 

Private Attributes

 $sort = 'relevance'
 

Detailed Description

Contain a class for special pages.

Definition at line 34 of file SearchEngine.php.

Member Function Documentation

SearchEngine::completionSearch (   $search)
SearchEngine::completionSearchBackend (   $search)
protected

Perform a completion search.

Does not resolve namespaces and does not check variants. Search engine implementations may want to override this function.

Parameters
string$search
Returns
SearchSuggestionSet

Definition at line 424 of file SearchEngine.php.

References SearchSuggestionSet\fromStrings(), SearchSuggestionSet\fromTitles(), namespaces, NS_SPECIAL, Hooks\run(), and simplePrefixSearch().

Referenced by completionSearch(), and completionSearchWithVariants().

SearchEngine::completionSearchWithVariants (   $search)

Perform a completion search with variants.

Parameters
string$search
Returns
SearchSuggestionSet

Definition at line 462 of file SearchEngine.php.

References $wgContLang, as, completionSearch(), completionSearchBackend(), SearchSuggestionSet\emptySuggestionSet(), global, normalizeNamespaces(), processCompletionResults(), and setLimitOffset().

static SearchEngine::create (   $type = null)
static

Load up the appropriate search engine class for the currently active database backend, and return a configured instance.

Deprecated:
since 1.27; Use SearchEngineFactory::create
Parameters
string$typeType of search backend, if not the default
Returns
SearchEngine

Definition at line 620 of file SearchEngine.php.

References $type.

static SearchEngine::defaultNamespaces ( )
static

An array of namespaces indexes to be searched by default.

Deprecated:
since 1.27; use SearchEngineConfig::defaultNamespaces()
Returns
array

Definition at line 598 of file SearchEngine.php.

static SearchEngine::defaultNearMatcher ( )
staticprotected

Get near matcher for default SearchEngine.

Returns
SearchNearMatcher

Definition at line 147 of file SearchEngine.php.

SearchEngine::defaultPrefixSearch (   $search)

Simple prefix search for subpages.

Parameters
string$search
Returns
Title[]

Definition at line 552 of file SearchEngine.php.

References normalizeNamespaces(), and simplePrefixSearch().

SearchEngine::delete (   $id,
  $title 
)

Delete an indexed page Title should be pre-processed.

STUB

Parameters
int$idPage id that was deleted
string$titleTitle of page that was deleted

Definition at line 339 of file SearchEngine.php.

SearchEngine::extractTitles ( SearchSuggestionSet  $completionResults)

Extract titles from completion results.

Parameters
SearchSuggestionSet$completionResults
Returns
Title[]

Definition at line 494 of file SearchEngine.php.

References SearchSuggestion\getSuggestedTitle(), and SearchSuggestionSet\map().

static SearchEngine::getNearMatch (   $searchterm)
static

If an exact title match can be found, or a very slightly close match, return the title.

If no match, returns NULL.

Deprecated:
since 1.27; Use SearchEngine::getNearMatcher()
Parameters
string$searchterm
Returns
Title

Definition at line 159 of file SearchEngine.php.

SearchEngine::getNearMatcher ( Config  $config)

Get service class to finding near matches.

Parameters
Config$configConfiguration to use for the matcher.
Returns
SearchNearMatcher

Definition at line 138 of file SearchEngine.php.

References $wgContLang, and global.

static SearchEngine::getNearMatchResultSet (   $searchterm)
static

Do a near match (see SearchEngine::getNearMatch) and wrap it into a SearchResultSet.

Deprecated:
since 1.27; Use SearchEngine::getNearMatcher()
Parameters
string$searchterm
Returns
SearchResultSet

Definition at line 170 of file SearchEngine.php.

static SearchEngine::getOpenSearchTemplate ( )
static

Get OpenSearch suggestion template.

Deprecated:
since 1.25
Returns
string

Definition at line 349 of file SearchEngine.php.

References ApiOpenSearch\getOpenSearchTemplate(), and wfDeprecated().

static SearchEngine::getSearchTypes ( )
static

Return the search engines we support.

If only $wgSearchType is set, it'll be an array of just that one item.

Deprecated:
since 1.27; use SearchEngineConfig::getSearchTypes()
Returns
array

Definition at line 630 of file SearchEngine.php.

SearchEngine::getSort ( )

Get the sort direction of the search results.

Since
1.25
Returns
string

Definition at line 258 of file SearchEngine.php.

References $sort.

SearchEngine::getTextFromContent ( Title  $t,
Content  $c = null 
)

Get the raw text for updating the index from a content object Nicer search backends could possibly do something cooler than just returning raw text.

Todo:
This isn't ideal, we'd really like to have content-specific handling here
Parameters
Title$tTitle we're indexing
Content$cContent of the page to index
Returns
string

Definition at line 364 of file SearchEngine.php.

SearchEngine::getValidSorts ( )

Get the valid sort directions.

All search engines support 'relevance' but others might support more. The default in all implementations should be 'relevance.'

Since
1.25
Returns
array(string) the valid sort directions for setSort

Definition at line 232 of file SearchEngine.php.

Referenced by setSort().

static SearchEngine::legalSearchChars ( )
static

Get chars legal for search.

NOTE: usage as static is deprecated and preserved only as BC measure

Returns
string

Definition at line 179 of file SearchEngine.php.

Referenced by SearchDatabase\filter(), SearchUpdate\getNormalizedTitle(), and SearchMssql\parseQuery().

static SearchEngine::namespacesAsText (   $namespaces)
static

Get a list of namespace names useful for showing in tooltips and preferences.

Deprecated:
since 1.27; use SearchEngineConfig::namespacesAsText()
Parameters
array$namespaces
Returns
array

Definition at line 609 of file SearchEngine.php.

SearchEngine::normalizeNamespaces (   $search)
protected

Makes search simple string if it was namespaced.

Sets namespaces of the search to namespaces extracted from string.

Parameters
string$search
Returns
string Simplified search string

Definition at line 385 of file SearchEngine.php.

References $namespaces, $title, Title\newFromText(), NS_FILE, NS_MAIN, NS_MEDIA, Hooks\run(), and setNamespaces().

Referenced by completionSearch(), completionSearchWithVariants(), and defaultPrefixSearch().

SearchEngine::normalizeText (   $string)

When overridden in derived class, performs database-specific conversions on text to be used for searching or updating search index.

Default implementation does nothing (simply returns $string).

Parameters
string$stringString to process
Returns
string

Definition at line 115 of file SearchEngine.php.

References $wgContLang, and global.

Referenced by SearchUpdate\getNormalizedTitle().

SearchEngine::processCompletionResults (   $search,
SearchSuggestionSet  $suggestions 
)
protected
SearchEngine::replacePrefixes (   $query)

Parse some common prefixes: all (search everything) or namespace names.

Parameters
string$query
Returns
string

Definition at line 269 of file SearchEngine.php.

References $query, $wgContLang, global, namespaces, and wfMessage().

static SearchEngine::searchableNamespaces ( )
static

Make a list of searchable namespaces and their canonical names.

Deprecated:
since 1.27; use SearchEngineConfig::searchableNamespaces()
Returns
array

Definition at line 578 of file SearchEngine.php.

Referenced by setNamespaces().

SearchEngine::searchText (   $term)

Perform a full text search query and return a result set.

If full text searches are not supported or disabled, return null. STUB

Parameters
string$termRaw search term
Returns
SearchResultSet|Status|null

Definition at line 65 of file SearchEngine.php.

SearchEngine::searchTitle (   $term)

Perform a title-only search query and return a result set.

If title searches are not supported or disabled, return null. STUB

Parameters
string$termRaw search term
Returns
SearchResultSet|null

Definition at line 77 of file SearchEngine.php.

SearchEngine::setFeatureData (   $feature,
  $data 
)

Way to pass custom data for engines.

Since
1.18
Parameters
string$feature
mixed$data
Returns
bool

Definition at line 103 of file SearchEngine.php.

SearchEngine::setLimitOffset (   $limit,
  $offset = 0 
)

Set the maximum number of results to return and how many to skip before returning the first.

Parameters
int$limit
int$offset

Definition at line 190 of file SearchEngine.php.

Referenced by completionSearchWithVariants(), and SearchEnginePrefixTest\testSearchBackend().

SearchEngine::setNamespaces (   $namespaces)

Set which namespaces the search should include.

Give an array of namespace index numbers.

Parameters
int[]|null$namespaces

Definition at line 201 of file SearchEngine.php.

References $namespaces, namespaces, searchableNamespaces(), and use.

Referenced by normalizeNamespaces().

SearchEngine::setShowSuggestion (   $showSuggestion)

Set whether the searcher should try to build a suggestion.

Note: some searchers don't support building a suggestion in the first place and others don't respect this flag.

Parameters
bool$showSuggestionShould the searcher try to build suggestions

Definition at line 221 of file SearchEngine.php.

References $showSuggestion.

SearchEngine::setSort (   $sort)

Set the sort direction of the search results.

Must be one returned by SearchEngine::getValidSorts()

Since
1.25
Exceptions
InvalidArgumentException
Parameters
string$sortsort direction for query result

Definition at line 244 of file SearchEngine.php.

References $sort, and getValidSorts().

SearchEngine::simplePrefixSearch (   $search)
protected

Call out to simple search backend.

Defaults to TitlePrefixSearch.

Parameters
string$search
Returns
Title[]

Definition at line 567 of file SearchEngine.php.

References PrefixSearch\defaultSearchBackend(), and namespaces.

Referenced by completionSearchBackend(), and defaultPrefixSearch().

SearchEngine::supports (   $feature)
Since
1.18
Parameters
string$feature
Returns
bool

Definition at line 86 of file SearchEngine.php.

SearchEngine::textAlreadyUpdatedForIndex ( )

If an implementation of SearchEngine handles all of its own text processing in getTextFromContent() and doesn't require SearchUpdate::updateText()'s rather silly handling, it should return true here instead.

Returns
bool

Definition at line 375 of file SearchEngine.php.

SearchEngine::transformSearchTerm (   $term)

Transform search term in cases when parts of the query came as different GET params (when supported), e.g.

for prefix queries: search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive

Parameters
string$term
Returns
string

Definition at line 129 of file SearchEngine.php.

References $term.

SearchEngine::update (   $id,
  $title,
  $text 
)

Create or update the search index record for the given page.

Title and text should be pre-processed. STUB

Parameters
int$id
string$title
string$text

Definition at line 315 of file SearchEngine.php.

SearchEngine::updateTitle (   $id,
  $title 
)

Update a search index record's title only.

Title should be pre-processed. STUB

Parameters
int$id
string$title

Definition at line 327 of file SearchEngine.php.

static SearchEngine::userHighlightPrefs ( )
static

Find snippet highlight settings for all users.

Returns
array Contextlines, contextchars

Definition at line 300 of file SearchEngine.php.

static SearchEngine::userNamespaces (   $user)
static

Extract default namespaces to search from the given user's settings, returning a list of index numbers.

Deprecated:
since 1.27; use SearchEngineConfig::userNamespaces()
Parameters
user$user
Returns
array

Definition at line 589 of file SearchEngine.php.

References $user.

Member Data Documentation

array SearchEngine::$features = []
protected

Feature values.

Definition at line 55 of file SearchEngine.php.

int SearchEngine::$limit = 10
protected

Definition at line 42 of file SearchEngine.php.

Referenced by SearchMySQL\limitResult().

int SearchEngine::$offset = 0
protected

Definition at line 45 of file SearchEngine.php.

Referenced by SearchMySQL\limitResult().

string SearchEngine::$prefix = ''

Definition at line 36 of file SearchEngine.php.

array string SearchEngine::$searchTerms = []
protected

Definition at line 48 of file SearchEngine.php.

bool SearchEngine::$showSuggestion = true
protected

Definition at line 51 of file SearchEngine.php.

Referenced by setShowSuggestion().

SearchEngine::$sort = 'relevance'
private

Definition at line 52 of file SearchEngine.php.

Referenced by getSort(), and setSort().


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