MediaWiki REL1_34
SearchMySQL Class Reference

Search engine hook for MySQL 4+. More...

Inheritance diagram for SearchMySQL:
Collaboration diagram for SearchMySQL:

Public Member Functions

 delete ( $id, $title)
 Delete an indexed page Title should be pre-processed.
 
 legalSearchChars ( $type=self::CHARS_ALL)
 Get chars legal for search.
 
 normalizeText ( $string)
 Converts some characters for MySQL's indexing to grok it correctly, and pads short words to overcome limitations.
 
 queryNamespaces (&$query)
 Add namespace conditions.
 
 supports ( $feature)
 
 update ( $id, $title, $text)
 Create or update the search index record for the given page.
 
 updateTitle ( $id, $title)
 Update a search index record's title only.
 
- Public Member Functions inherited from SearchDatabase
 __construct (ILoadBalancer $lb)
 
 doSearchText ( $term)
 
 doSearchTitle ( $term)
 
- Public Member Functions inherited from SearchEngine
 augmentSearchResults (ISearchResultSet $resultSet)
 Augment search results with extra data.
 
 completionSearch ( $search)
 Perform a completion search.
 
 completionSearchWithVariants ( $search)
 Perform a completion search with variants.
 
 defaultPrefixSearch ( $search)
 Simple prefix search for subpages.
 
 extractTitles (SearchSuggestionSet $completionResults)
 Extract titles from completion results.
 
 getFeatureData ( $feature)
 Way to retrieve custom data set by setFeatureData or by the engine itself.
 
 getNearMatcher (Config $config)
 Get service class to finding near matches.
 
 getProfiles ( $profileType, User $user=null)
 Get a list of supported profiles.
 
 getSearchIndexFields ()
 Get fields for search index.
 
 getSort ()
 Get the sort direction of the search results.
 
 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.
 
 getValidSorts ()
 Get the valid sort directions.
 
 makeSearchFieldMapping ( $name, $type)
 Create a search field definition.
 
 replacePrefixes ( $query)
 Parse some common prefixes: all (search everything) or namespace names and set the list of namespaces of this class accordingly.
 
 searchArchiveTitle ( $term)
 Perform a title search in the article archive.
 
 searchText ( $term)
 Perform a full text search query and return a result set.
 
 searchTitle ( $term)
 Perform a title-only search query and return a result set.
 
 setFeatureData ( $feature, $data)
 Way to pass custom data for engines.
 
 setLimitOffset ( $limit, $offset=0)
 Set the maximum number of results to return and how many to skip before returning the first.
 
 setNamespaces ( $namespaces)
 Set which namespaces the search should include.
 
 setShowSuggestion ( $showSuggestion)
 Set whether the searcher should try to build a suggestion.
 
 setSort ( $sort)
 Set the sort direction of the search results.
 
 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.
 

Protected Member Functions

 doSearchTextInDB ( $term)
 Perform a full text search query and return a result set.
 
 doSearchTitleInDB ( $term)
 Perform a title-only search query and return a result set.
 
 limitResult (&$query)
 Add limit options.
 
 minSearchLength ()
 Check MySQL server's ft_min_word_len setting so we know if we need to pad short words...
 
 queryFeatures (&$query)
 Add special conditions.
 
 searchInternal ( $term, $fulltext)
 
 stripForSearchCallback ( $matches)
 Armor a case-folded UTF-8 string to get through MySQL's fulltext search without being mucked up by funny charset settings or anything else of the sort.
 
- Protected Member Functions inherited from SearchDatabase
 extractNamespacePrefix ( $term)
 Extract the optional namespace prefix and set self::namespaces accordingly and return the query string.
 
 filter ( $text)
 Return a 'cleaned up' search string.
 
- Protected Member Functions inherited from SearchEngine
 completionSearchBackend ( $search)
 Perform a completion search.
 
 completionSearchBackendOverfetch ( $search)
 Perform an overfetch of completion search results.
 
 doSearchArchiveTitle ( $term)
 Perform a title search in the article archive.
 
 normalizeNamespaces ( $search)
 Makes search simple string if it was namespaced.
 
 processCompletionResults ( $search, SearchSuggestionSet $suggestions)
 Process completion search results.
 
 simplePrefixSearch ( $search)
 Call out to simple search backend.
 

Protected Attributes

 $strictMatching = true
 
- Protected Attributes inherited from SearchDatabase
IDatabase $db
 (backwards compatibility)
 
ILoadBalancer $lb
 
string[] $searchTerms = []
 search terms
 
- Protected Attributes inherited from SearchEngine
array $features = []
 Feature values.
 
int $limit = 10
 
int $offset = 0
 
string[] $searchTerms = []
 
bool $showSuggestion = true
 

Private Member Functions

 getCountQuery ( $filteredTerm, $fulltext)
 
 getIndexField ( $fulltext)
 Picks which field to index on, depending on what type of query.
 
 getQuery ( $filteredTerm, $fulltext)
 Construct the SQL query to do the search.
 
 parseQuery ( $filteredText, $fulltext)
 Parse the user's query and transform it into two SQL fragments: a WHERE condition and an ORDER BY expression.
 
 queryMain (&$query, $filteredTerm, $fulltext)
 Get the base part of the search query.
 
 regexTerm ( $string, $wildcard)
 

Static Private Attributes

static $mMinSearchLength
 

Additional Inherited Members

- Static Public Member Functions inherited from SearchEngine
static parseNamespacePrefixes ( $query, $withAllKeyword=true, $withPrefixSearchExtractNamespaceHook=false)
 Parse some common prefixes: all (search everything) or namespace names.
 
static userHighlightPrefs ()
 Find snippet highlight settings for all users.
 
- Public Attributes inherited from SearchEngine
int[] null $namespaces = [ NS_MAIN ]
 
string $prefix = ''
 
const CHARS_ALL = 1
 Integer flag for legalSearchChars: includes all chars allowed in a search query.
 
const CHARS_NO_SYNTAX = 2
 Integer flag for legalSearchChars: includes all chars allowed in a search term.
 
const COMPLETION_PROFILE_TYPE = 'completionSearchProfile'
 Profile type for completionSearch.
 
const DEFAULT_SORT = 'relevance'
 
const FT_QUERY_INDEP_PROFILE_TYPE = 'fulltextQueryIndepProfile'
 Profile type for query independent ranking features.
 
- Static Protected Member Functions inherited from SearchEngine
static defaultNearMatcher ()
 Get near matcher for default SearchEngine.
 

Detailed Description

Search engine hook for MySQL 4+.

Definition at line 33 of file SearchMySQL.php.

Member Function Documentation

◆ delete()

SearchMySQL::delete ( $id,
$title )

Delete an indexed page Title should be pre-processed.

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

Reimplemented from SearchEngine.

Definition at line 378 of file SearchMySQL.php.

References DB_MASTER.

◆ doSearchTextInDB()

SearchMySQL::doSearchTextInDB ( $term)
protected

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

Parameters
string$termRaw search term
Returns
SqlSearchResultSet|null

Reimplemented from SearchDatabase.

Definition at line 168 of file SearchMySQL.php.

References searchInternal().

◆ doSearchTitleInDB()

SearchMySQL::doSearchTitleInDB ( $term)
protected

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

Parameters
string$termRaw search term
Returns
SqlSearchResultSet|null

Reimplemented from SearchDatabase.

Definition at line 178 of file SearchMySQL.php.

References searchInternal().

◆ getCountQuery()

SearchMySQL::getCountQuery ( $filteredTerm,
$fulltext )
private
Since
1.18 (changed)
Parameters
string$filteredTerm
bool$fulltext
Returns
array

Definition at line 319 of file SearchMySQL.php.

References parseQuery(), queryFeatures(), and queryNamespaces().

Referenced by searchInternal().

◆ getIndexField()

SearchMySQL::getIndexField ( $fulltext)
private

Picks which field to index on, depending on what type of query.

Parameters
bool$fulltext
Returns
string

Definition at line 289 of file SearchMySQL.php.

Referenced by parseQuery().

◆ getQuery()

SearchMySQL::getQuery ( $filteredTerm,
$fulltext )
private

Construct the SQL query to do the search.

The guts shoulds be constructed in queryMain()

Parameters
string$filteredTerm
bool$fulltext
Returns
array
Since
1.18 (changed)

Definition at line 267 of file SearchMySQL.php.

References limitResult(), queryFeatures(), queryMain(), and queryNamespaces().

Referenced by searchInternal().

◆ legalSearchChars()

SearchMySQL::legalSearchChars ( $type = self::CHARS_ALL)

Get chars legal for search.

Parameters
int$typetype of search chars (see self::CHARS_ALL and self::CHARS_NO_SYNTAX). Defaults to CHARS_ALL
Returns
string

Reimplemented from SearchEngine.

Definition at line 153 of file SearchMySQL.php.

References $type.

Referenced by parseQuery().

◆ limitResult()

SearchMySQL::limitResult ( & $query)
protected

Add limit options.

Parameters
array&$query
Since
1.18

Definition at line 254 of file SearchMySQL.php.

References SearchEngine\$limit, and SearchEngine\$offset.

Referenced by getQuery().

◆ minSearchLength()

SearchMySQL::minSearchLength ( )
protected

Check MySQL server's ft_min_word_len setting so we know if we need to pad short words...

Returns
int

Definition at line 441 of file SearchMySQL.php.

References $dbr, $mMinSearchLength, and DB_REPLICA.

Referenced by normalizeText().

◆ normalizeText()

SearchMySQL::normalizeText ( $string)

Converts some characters for MySQL's indexing to grok it correctly, and pads short words to overcome limitations.

Parameters
string$string
Returns
mixed|string

Reimplemented from SearchEngine.

Definition at line 389 of file SearchMySQL.php.

References minSearchLength().

Referenced by parseQuery(), update(), and updateTitle().

◆ parseQuery()

SearchMySQL::parseQuery ( $filteredText,
$fulltext )
private

Parse the user's query and transform it into two SQL fragments: a WHERE condition and an ORDER BY expression.

Parameters
string$filteredText
string$fulltext
Returns
array

Definition at line 47 of file SearchMySQL.php.

References $dbr, DB_REPLICA, getIndexField(), legalSearchChars(), normalizeText(), regexTerm(), and wfDebug().

Referenced by getCountQuery(), and queryMain().

◆ queryFeatures()

SearchMySQL::queryFeatures ( & $query)
protected

Add special conditions.

Parameters
array&$query
Since
1.18

Definition at line 226 of file SearchMySQL.php.

References $dbr, and DB_REPLICA.

Referenced by getCountQuery(), and getQuery().

◆ queryMain()

SearchMySQL::queryMain ( & $query,
$filteredTerm,
$fulltext )
private

Get the base part of the search query.

Parameters
array&$querySearch query array
string$filteredTerm
bool$fulltext
Since
1.18 (changed)

Definition at line 301 of file SearchMySQL.php.

References parseQuery().

Referenced by getQuery().

◆ queryNamespaces()

SearchMySQL::queryNamespaces ( & $query)

Add namespace conditions.

Parameters
array&$query
Since
1.18 (changed)

Definition at line 240 of file SearchMySQL.php.

References SearchEngine\$namespaces.

Referenced by getCountQuery(), and getQuery().

◆ regexTerm()

SearchMySQL::regexTerm ( $string,
$wildcard )
private

Definition at line 136 of file SearchMySQL.php.

Referenced by parseQuery().

◆ searchInternal()

SearchMySQL::searchInternal ( $term,
$fulltext )
protected

Definition at line 182 of file SearchMySQL.php.

References $dbr, DB_REPLICA, SearchDatabase\filter(), getCountQuery(), and getQuery().

Referenced by doSearchTextInDB(), and doSearchTitleInDB().

◆ stripForSearchCallback()

SearchMySQL::stripForSearchCallback ( $matches)
protected

Armor a case-folded UTF-8 string to get through MySQL's fulltext search without being mucked up by funny charset settings or anything else of the sort.

Parameters
array$matches
Returns
string

Definition at line 431 of file SearchMySQL.php.

References $matches.

◆ supports()

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

Reimplemented from SearchEngine.

Definition at line 212 of file SearchMySQL.php.

◆ update()

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

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

Title and text should be pre-processed.

Parameters
int$id
string$title
string$text

Reimplemented from SearchEngine.

Definition at line 344 of file SearchMySQL.php.

References $title, DB_MASTER, and normalizeText().

◆ updateTitle()

SearchMySQL::updateTitle ( $id,
$title )

Update a search index record's title only.

Title should be pre-processed.

Parameters
int$id
string$title

Reimplemented from SearchEngine.

Definition at line 362 of file SearchMySQL.php.

References $title, DB_MASTER, and normalizeText().

Member Data Documentation

◆ $mMinSearchLength

SearchMySQL::$mMinSearchLength
staticprivate

Definition at line 36 of file SearchMySQL.php.

Referenced by minSearchLength().

◆ $strictMatching

SearchMySQL::$strictMatching = true
protected

Definition at line 34 of file SearchMySQL.php.


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