\SearchWordsSQLSQLBuilder

Builds SQL and IBL from search words.

Summary

Methods
Properties
Constants
__construct()
Build()
isComplement()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(string $wordSQL, callable $valueCallback, callable $IBLCallback, callback[] $prefixCallbacks)

A constructor.

A constructor.

Parameters

string $wordSQL

A parameterized SQL boolean expression using placeholder(s) for each search word.

callable $valueCallback

A user function with a parameter to convert a search word. If omitted, no conversion will be processed. It would be given an original search word as the first parameter and must return a converted value, which if $thisobj were an instance of SQLBuilder, $thisobj->Build()['value'] would contain. The return value can be an array.

callable $IBLCallback

A user function with a parameter to convert a search word. If omitted, \SearchWordsSQL\IBLCallback() is used. It would be given an original search word as the first parameter and must return a converted value, which if $thisobj were an instance of SQLBuilder, $thisobj->Build()['IBL'] would contain. The return value can be an array.

callback[] $prefixCallbacks

An array containing prefix functions with keys to specify prefix. A prefix function will be called when a search word contains the prefix at the beginning. The prefix function must return an array containing an SQL string with key 'SQL' and an value with key 'value'.

Build()

Build(string $wordsline) : array

Converts search words into SQL and IBL.

Converts search words into SQL and IBL.

Parameters

string $wordsline

Search words in the syntax described on readme.md.

Throws

\InvalidArgumentException

if the search words has syntax error(s).

Returns

array —

Key 'SQL': an SQL parameterized expression. Key 'IBL': an IBL expression. Key 'value': Values for paramaters for the SQL expression. Key 'hit': an array consisted of possible hit words.

isComplement()

isComplement(array $tree)

Returns whether built result is complement.

Estimates whether built result is complement. For example, a search word '-word1' is complement, whereas '-word1 word2' is not complement. In most cases, search words which are complement is inappropriate for search.

Parameters

array $tree

This must be omitted.