MediaWiki  1.23.15
SearchEngine Class Reference

Contain a class for special pages. More...

Inheritance diagram for SearchEngine:

Public Member Functions

 delete ( $id, $title)
 Delete an indexed page Title should be pre-processed. More...
 
 filter ( $text)
 Return a 'cleaned up' search string. 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...
 
 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...
 
 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 helpNamespaces ()
 Return the help namespaces to be shown on Special:Search. More...
 
static legalSearchChars ()
 
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

 $limit = 10
 
 $namespaces = array( NS_MAIN )
 
 $offset = 0
 
 $prefix = ''
 
 $searchTerms = array()
 

Protected Attributes

Array $features = array()
 Feature values *. More...
 
 $showSuggestion = true
 

Static Private Member Functions

static getNearMatchInternal ( $searchterm)
 Really find the title match. More...
 

Detailed Description

Contain a class for special pages.

Definition at line 32 of file SearchEngine.php.

Member Function Documentation

◆ create()

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

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

Parameters
String$typeType of search backend, if not the default
Returns
SearchEngine

Definition at line 447 of file SearchEngine.php.

References $dbr, $type, DB_SLAVE, getSearchTypes(), global, and wfGetDB().

Referenced by SpecialSearch\getSearchEngine(), SearchResult\initText(), and ApiQuerySearch\run().

◆ defaultNamespaces()

static SearchEngine::defaultNamespaces ( )
static

An array of namespaces indexes to be searched by default.

Returns
Array

Definition at line 393 of file SearchEngine.php.

References global.

Referenced by getOpenSearchTemplate(), SpecialSearch\getSearchProfiles(), and SpecialSearchTest\provideSearchOptionsTests().

◆ delete()

SearchEngine::delete (   $id,
  $title 
)

Delete an indexed page Title should be pre-processed.

STUB

Parameters
Integer$idPage id that was deleted
String$titleTitle of page that was deleted

Reimplemented in SearchMySQL.

Definition at line 514 of file SearchEngine.php.

◆ filter()

SearchEngine::filter (   $text)

Return a 'cleaned up' search string.

Parameters
$textString
Returns
String

Definition at line 435 of file SearchEngine.php.

References legalSearchChars().

Referenced by SearchSqlite\searchInternal(), and SearchMySQL\searchInternal().

◆ getNearMatch()

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.

Parameters
$searchtermString
Returns
Title

Definition at line 122 of file SearchEngine.php.

References $title, array(), getNearMatchInternal(), and wfRunHooks().

Referenced by getNearMatchInternal(), and SpecialSearch\goResult().

◆ getNearMatchInternal()

static SearchEngine::getNearMatchInternal (   $searchterm)
staticprivate

◆ getNearMatchResultSet()

static SearchEngine::getNearMatchResultSet (   $searchterm)
static

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

Parameters
$searchtermstring
Returns
SearchResultSet

Definition at line 136 of file SearchEngine.php.

Referenced by ApiQuerySearch\run().

◆ getOpenSearchTemplate()

static SearchEngine::getOpenSearchTemplate ( )
static

Get OpenSearch suggestion template.

Returns
String

Definition at line 523 of file SearchEngine.php.

References defaultNamespaces(), global, and wfScript().

◆ getSearchTypes()

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.

Returns
array

Definition at line 472 of file SearchEngine.php.

References array(), and global.

Referenced by create(), ApiQuerySearch\getAllowedParams(), and ApiQuerySearch\getParamDescription().

◆ getTextFromContent()

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 546 of file SearchEngine.php.

◆ helpNamespaces()

static SearchEngine::helpNamespaces ( )
static

Return the help namespaces to be shown on Special:Search.

Returns
Array

Definition at line 423 of file SearchEngine.php.

References global.

Referenced by SpecialSearch\getSearchProfiles().

◆ legalSearchChars()

static SearchEngine::legalSearchChars ( )
static

◆ namespacesAsText()

static SearchEngine::namespacesAsText (   $namespaces)
static

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

Parameters
$namespacesArray
Returns
array

Definition at line 406 of file SearchEngine.php.

References $namespaces, $wgContLang, array(), as, global, and wfMessage().

Referenced by SpecialSearch\getSearchProfiles().

◆ normalizeText()

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

Reimplemented in SearchMySQL.

Definition at line 100 of file SearchEngine.php.

References $wgContLang, and global.

◆ replacePrefixes()

SearchEngine::replacePrefixes (   $query)

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

Parameters
$queryString
Returns
string

Definition at line 300 of file SearchEngine.php.

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

◆ searchableNamespaces()

static SearchEngine::searchableNamespaces ( )
static

Make a list of searchable namespaces and their canonical names.

Returns
Array

Definition at line 334 of file SearchEngine.php.

References $name, $wgContLang, array(), as, global, NS_MAIN, and wfRunHooks().

Referenced by User\getDefaultOptions(), SpecialSearch\getSearchProfiles(), Preferences\loadOldSearchNs(), SpecialSearch\powerSearch(), SpecialSearch\powerSearchBox(), and userNamespaces().

◆ searchText()

SearchEngine::searchText (   $term)

Perform a full text 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|Status|null

Reimplemented in SearchMySQL, SearchSqlite, SearchOracle, SearchPostgres, and SearchMssql.

Definition at line 50 of file SearchEngine.php.

◆ searchTitle()

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

Reimplemented in SearchMySQL, SearchSqlite, SearchOracle, SearchMssql, and SearchPostgres.

Definition at line 62 of file SearchEngine.php.

◆ setFeatureData()

SearchEngine::setFeatureData (   $feature,
  $data 
)

Way to pass custom data for engines.

Since
1.18
Parameters
$featureString
$dataMixed
Returns
bool

Definition at line 88 of file SearchEngine.php.

◆ setLimitOffset()

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

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

Parameters
$limitInteger
$offsetInteger

Definition at line 267 of file SearchEngine.php.

References $limit, and $offset.

◆ setNamespaces()

SearchEngine::setNamespaces (   $namespaces)

Set which namespaces the search should include.

Give an array of namespace index numbers.

Parameters
$namespacesArray

Definition at line 278 of file SearchEngine.php.

References $namespaces, and namespaces.

◆ setShowSuggestion()

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
boolean$showSuggestionshould the searcher try to build suggestions

Definition at line 289 of file SearchEngine.php.

References $showSuggestion.

◆ supports()

SearchEngine::supports (   $feature)
Since
1.18
Parameters
$featureString
Returns
Boolean

Reimplemented in SearchMySQL.

Definition at line 71 of file SearchEngine.php.

◆ textAlreadyUpdatedForIndex()

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 557 of file SearchEngine.php.

◆ transformSearchTerm()

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

Definition at line 111 of file SearchEngine.php.

References $term.

◆ update()

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
$idInteger
$titleString
$textString

Reimplemented in SearchPostgres, SearchMySQL, SearchSqlite, SearchOracle, SearchMssql, and MockSearch.

Definition at line 490 of file SearchEngine.php.

◆ updateTitle()

SearchEngine::updateTitle (   $id,
  $title 
)

Update a search index record's title only.

Title should be pre-processed. STUB

Parameters
$idInteger
$titleString

Reimplemented in SearchMySQL, SearchSqlite, SearchOracle, SearchPostgres, and SearchMssql.

Definition at line 502 of file SearchEngine.php.

◆ userHighlightPrefs()

static SearchEngine::userHighlightPrefs ( )
static

Find snippet highlight settings for all users.

Returns
Array contextlines, contextchars

Definition at line 382 of file SearchEngine.php.

References array().

Referenced by SearchResult\getTextSnippet().

◆ userNamespaces()

static SearchEngine::userNamespaces (   $user)
static

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

Parameters
$userUser
Returns
Array

Definition at line 354 of file SearchEngine.php.

References $name, $user, array(), as, global, and searchableNamespaces().

Referenced by SpecialSearch\load().

Member Data Documentation

◆ $features

Array SearchEngine::$features = array()
protected

Feature values *.

Definition at line 40 of file SearchEngine.php.

◆ $limit

SearchEngine::$limit = 10

Definition at line 33 of file SearchEngine.php.

Referenced by SearchMySQL\limitResult(), and setLimitOffset().

◆ $namespaces

◆ $offset

SearchEngine::$offset = 0

Definition at line 34 of file SearchEngine.php.

Referenced by SearchMySQL\limitResult(), and setLimitOffset().

◆ $prefix

SearchEngine::$prefix = ''

Definition at line 35 of file SearchEngine.php.

Referenced by replacePrefixes().

◆ $searchTerms

SearchEngine::$searchTerms = array()

Definition at line 36 of file SearchEngine.php.

◆ $showSuggestion

SearchEngine::$showSuggestion = true
protected

Definition at line 38 of file SearchEngine.php.

Referenced by setShowSuggestion().


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