CirrusSearch
Elasticsearch-powered search for MediaWiki
Loading...
Searching...
No Matches
CirrusSearch\Search\Escaper Class Reference

Escapes queries. More...

Public Member Functions

 __construct ( $language, $allowLeadingWildcard=true)
 
 escapeQuotes ( $text)
 
 fixupQueryStringPart ( $string)
 Make sure the query string part is well formed by escaping some syntax that we don't want users to get direct access to and making sure quotes are balanced.
 
 balanceQuotes ( $text)
 
 unbalancedQuotes ( $text, $from=0, $to=-1)
 
 unescape ( $query, $escapeChar='\\')
 Unescape a given string.
 
 getAllowLeadingWildcard ()
 Is leading wildcard allowed?
 
 getLanguage ()
 

Detailed Description

Escapes queries.

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

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\Search\Escaper::__construct ( $language,
$allowLeadingWildcard = true )
Parameters
string$languageMediaWiki language code
bool$allowLeadingWildcard

Member Function Documentation

◆ balanceQuotes()

CirrusSearch\Search\Escaper::balanceQuotes ( $text)
Parameters
string$text
Returns
string

◆ escapeQuotes()

CirrusSearch\Search\Escaper::escapeQuotes ( $text)
Parameters
string$text
Returns
string

◆ fixupQueryStringPart()

CirrusSearch\Search\Escaper::fixupQueryStringPart ( $string)

Make sure the query string part is well formed by escaping some syntax that we don't want users to get direct access to and making sure quotes are balanced.

These special characters aren't escaped:

  • and ?: Do a wildcard search against the stemmed text which isn't strictly a good idea but this is so rarely used that adding extra code to flip prefix searches into real prefix searches isn't really worth it. ~: Do a fuzzy match against the stemmed text which isn't strictly a good idea but it gets the job done and fuzzy matches are a really rarely used feature to be creating an extra index for. ": Perform a phrase search for the quoted term. If the "s aren't balanced we insert one at the end of the term to make sure elasticsearch doesn't barf at us.
Parameters
string$string
Returns
string

◆ getAllowLeadingWildcard()

CirrusSearch\Search\Escaper::getAllowLeadingWildcard ( )

Is leading wildcard allowed?

Returns
bool

◆ getLanguage()

CirrusSearch\Search\Escaper::getLanguage ( )
Returns
string

◆ unbalancedQuotes()

CirrusSearch\Search\Escaper::unbalancedQuotes ( $text,
$from = 0,
$to = -1 )
Parameters
string$text
int$from
int$to
Returns
bool true if there are unbalanced quotes in the [$from, $to] range.

◆ unescape()

CirrusSearch\Search\Escaper::unescape ( $query,
$escapeChar = '\\' )

Unescape a given string.

Parameters
string$querystring to unescape
string$escapeCharescape sequence
Returns
string

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