Documentation

SearchParser
in package

This class provides a parser which can construct an SQL WHERE clause from a Google-like search expression.

The expression recognizes boolean "AND", "OR", and "NOT" (providing no operator between keywords implies "AND"), like so:

cat and dog cat or dog cat and not dog

If no operator appears between keywords or quoted strings, "AND" is assumed. A comma can be used instead of "OR":

cat dog cat, dog cat not dog

The parser recognizes parentheses, so complex expressions can be created:

cat and not (dog or puppy)

Quoted strings are also recognized, and are taken as literal keywords:

"cat and dog"

Parsing is designed to be as fuzzy as possible, so it shouldn't error unless people search for "AND", "OR", or "NOT" without quoting it or use unbalanced parentheses.

Tags
author

Jason M. Felice jason.m.felice@gmail.com

category

Horde

copyright

2004-2021 Horde LLC

license

http://www.horde.org/licenses/bsd

Table of Contents

parse()  : string
Parses a keyword expression.
parseKeywords1()  : mixed
parseKeywords2()  : mixed
parseKeywords3()  : mixed
parseKeywords4()  : mixed

Methods

parse()

Parses a keyword expression.

public static parse(string $column, string $expr) : string
Parameters
$column : string

This is the SQL field name the resulting expression should test against.

$expr : string

This is the keyword expression we want to parse.

Tags
throws
DbException
Return values
string

The query expression.

parseKeywords1()

protected static parseKeywords1(mixed $column, mixed &$tokens) : mixed
Parameters
$column : mixed
$tokens : mixed
Return values
mixed

parseKeywords2()

protected static parseKeywords2(mixed $column, mixed &$tokens) : mixed
Parameters
$column : mixed
$tokens : mixed
Return values
mixed

parseKeywords3()

protected static parseKeywords3(mixed $column, mixed &$tokens) : mixed
Parameters
$column : mixed
$tokens : mixed
Return values
mixed

parseKeywords4()

protected static parseKeywords4(mixed $column, mixed &$tokens) : mixed
Parameters
$column : mixed
$tokens : mixed
Return values
mixed

Search results