Class Horde_SQL_Keywords

Description

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

$Horde: framework/SQL/SQL/Keywords.php,v 1.2.10.9 2009/01/06 15:23:33 jan Exp $

Copyright 2004-2009 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.

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.

Located in /SQL/SQL/Keywords.php (line 45)


	
			
Method Summary
 mixed parse (string $column, string $expr)
 void _parseKeywords1 ( $column,  &$tokens)
 void _parseKeywords2 ( $column,  &$tokens)
 void _parseKeywords3 ( $column,  &$tokens)
 void _parseKeywords4 ( $column,  &$tokens)
Methods
parse (line 56)

Parse a keyword expression.

  • return: the query expression or a PEAR_Error on failure.
mixed parse (string $column, string $expr)
  • string $column: This is the SQL field name the resulting expression should test against.
  • string $expr: This is the keyword expression we want to parse.
_parseKeywords1 (line 110)
void _parseKeywords1 ( $column,  &$tokens)
  • $column
  • &$tokens
_parseKeywords2 (line 130)
void _parseKeywords2 ( $column,  &$tokens)
  • $column
  • &$tokens
_parseKeywords3 (line 146)
void _parseKeywords3 ( $column,  &$tokens)
  • $column
  • &$tokens
_parseKeywords4 (line 159)
void _parseKeywords4 ( $column,  &$tokens)
  • $column
  • &$tokens

Documentation generated on Sun, 30 Jan 2011 05:18:41 +0000 by phpDocumentor 1.4.3