SearchWordsSQL.php

SearchWordsSQL

A library to convert a Google-style query of seach words into an SQL boolean expression and a MySQL IBL (a.k.a. 'Implied Boolean Logic' or 'IN BOOLEAN MODE') one.

Classes

SQLBuilder Builds SQL and IBL from search words.

Functions

SQLLikeValueCallback()

SQLLikeValueCallback(string $value) : string

A sample SQL-value callback function suitable for SQL LIKE operator

Escapes meta characters for LIKE operator and replaces '*' to '%'. Also prepends and appends '%'.

Parameters

string $value

An original word.

Returns

string —

A converted value.

IBLCallback()

IBLCallback(string $value) : string

The standard IBL callback function

Removes meta characters of IBL.

Parameters

string $value

An original word.

Returns

string —

A converted value.

ReplicateDataType()

ReplicateDataType(array $values, string $typename, int $multiplier) : string[]

Duplicates string (the number of values X multiplier) times into an array.

A utility function suitable for MDB2 prepare(). This might be useful when the parameter $wordSQL of SQLBuilder::__construct() has plural placeholders.

Parameters

array $values

Values for a prepared query, returned by Build().

string $typename

Typename for a word.

int $multiplier

The number of parameters per word.

Returns

string[] —

Replicated typenames.

array_flatten()

array_flatten(array $a) : \SearchWordsSQL\Parser\The

Flattens an array tree.

A utility function to flatten an array which contains data in a tree structure. This can be useful to prepare a parameterized SQL statement when the callback function returns an array whereas the parameters must be a flat array to prepare. Note that empty array are ignored.

Parameters

array $a

An array to be flatten.

Returns

\SearchWordsSQL\Parser\The —

flattened array.