CRM_Utils_QueryFormatter
in package
Class CRM_Utils_QueryFormatter
This class is a bad idea. It exists for the unholy reason that a single installation may have up to three query engines (MySQL LIKE, MySQL FTS, Solr) processing the same query-text. It labors* to take the user's search expression and provide similar search semantics in different contexts. It is unknown whether this labor will be fruitful or in vain.
Table of Contents
Constants
- LANG_SOLR = 'solr'
- Generate queries using Solr expressions.
- LANG_SQL_FTS = 'fts'
- Generate queries using MySQL FTS expressions.
- LANG_SQL_FTSBOOL = 'ftsbool'
- Generate queries using MySQL's boolean FTS expressions.
- LANG_SQL_LIKE = 'like'
- Generate queries using SQL LIKE expressions.
- MODE_NONE = 'simple'
- Attempt to leave the text as-is.
- MODE_PHRASE = 'phrase'
- Attempt to treat the input text as a phrase
- MODE_WILDPHRASE = 'wildphrase'
- Attempt to treat the input text as a phrase with wildcards on each end.
- MODE_WILDWORDS = 'wildwords'
- Attempt to treat individual word as if it had wildcards at the start and end.
- MODE_WILDWORDS_SUFFIX = 'wildwords-suffix'
- Attempt to treat individual word as if it had a wildcard at the end.
Properties
- $mode : string
- $singleton : CRM_Utils_QueryFormatter|null
- Singleton object.
Methods
- __construct() : mixed
- dumpExampleTable() : mixed
- format() : string
- formatSql() : string
- Create a SQL WHERE expression for matching against a list of text columns.
- getLanguages() : array<string|int, mixed>
- Get languages.
- getMode() : mixed
- getModes() : array<string|int, mixed>
- Get modes.
- setMode() : mixed
- singleton() : CRM_Utils_QueryFormatter
- _formatFts() : mixed
- Format Fts.
- _formatFtsBool() : mixed
- Format FTS.
- _formatLike() : mixed
- Format like.
- dedupeWildcards() : string|null
- mapWords() : string
- parseWords() : array<string|int, mixed>
Constants
LANG_SOLR
Generate queries using Solr expressions.
public
mixed
LANG_SOLR
= 'solr'
LANG_SQL_FTS
Generate queries using MySQL FTS expressions.
public
mixed
LANG_SQL_FTS
= 'fts'
LANG_SQL_FTSBOOL
Generate queries using MySQL's boolean FTS expressions.
public
mixed
LANG_SQL_FTSBOOL
= 'ftsbool'
LANG_SQL_LIKE
Generate queries using SQL LIKE expressions.
public
mixed
LANG_SQL_LIKE
= 'like'
MODE_NONE
Attempt to leave the text as-is.
public
mixed
MODE_NONE
= 'simple'
MODE_PHRASE
Attempt to treat the input text as a phrase
public
mixed
MODE_PHRASE
= 'phrase'
MODE_WILDPHRASE
Attempt to treat the input text as a phrase with wildcards on each end.
public
mixed
MODE_WILDPHRASE
= 'wildphrase'
MODE_WILDWORDS
Attempt to treat individual word as if it had wildcards at the start and end.
public
mixed
MODE_WILDWORDS
= 'wildwords'
MODE_WILDWORDS_SUFFIX
Attempt to treat individual word as if it had a wildcard at the end.
public
mixed
MODE_WILDWORDS_SUFFIX
= 'wildwords-suffix'
Properties
$mode
protected
string
$mode
eg MODE_NONE
$singleton
Singleton object.
protected
static CRM_Utils_QueryFormatter|null
$singleton
Methods
__construct()
public
__construct(string $mode) : mixed
Parameters
- $mode : string
-
Eg MODE_NONE.
dumpExampleTable()
public
static dumpExampleTable(string $text) : mixed
Parameters
- $text : string
-
Ex: drush eval 'civicrm_initialize(); CRM_Utils_QueryFormatter::dumpExampleTable("firstword secondword");'
format()
public
format(string $text, string $language) : string
Parameters
- $text : string
- $language : string
-
Eg LANG_SQL_LIKE, LANG_SQL_FTS, LANG_SOLR.
Tags
Return values
stringformatSql()
Create a SQL WHERE expression for matching against a list of text columns.
public
formatSql(string $table, array<string|int, mixed>|string $columns, string $queryText) : string
Parameters
- $table : string
-
Eg "civicrm_note" or "civicrm_note mynote".
- $columns : array<string|int, mixed>|string
-
List of columns to search against. Eg "first_name" or "activity_details".
- $queryText : string
Return values
string —SQL, eg "MATCH (col1) AGAINST (queryText)" or "col1 LIKE '%queryText%'"
getLanguages()
Get languages.
public
static getLanguages() : array<string|int, mixed>
Return values
array<string|int, mixed>getMode()
public
getMode() : mixed
getModes()
Get modes.
public
static getModes() : array<string|int, mixed>
Return values
array<string|int, mixed>setMode()
public
setMode(mixed $mode) : mixed
Parameters
- $mode : mixed
singleton()
public
static singleton([bool $fresh = FALSE ]) : CRM_Utils_QueryFormatter
Parameters
- $fresh : bool = FALSE
Return values
CRM_Utils_QueryFormatter_formatFts()
Format Fts.
protected
_formatFts(string $text, string $mode) : mixed
Parameters
- $text : string
- $mode : string
_formatFtsBool()
Format FTS.
protected
_formatFtsBool(string $text, string $mode) : mixed
Parameters
- $text : string
- $mode : string
_formatLike()
Format like.
protected
_formatLike(string $text, string $mode) : mixed
Parameters
- $text : string
- $mode : string
dedupeWildcards()
protected
dedupeWildcards(string|null $text, string $wildcard) : string|null
Parameters
- $text : string|null
- $wildcard : string
Return values
string|nullmapWords()
protected
mapWords(string $text, string $template[, bool $quotes = FALSE ]) : string
Parameters
- $text : string
-
User-supplied query string.
- $template : string
-
A prototypical description of each word, eg "word%" or "word*" or "word".
- $quotes : bool = FALSE
-
True if each searched keyword need to be surrounded with quotes.
Return values
stringparseWords()
protected
parseWords(string $text, bool $quotes) : array<string|int, mixed>
Parameters
- $text : string
- $quotes : bool