SnapSearch Class Reference
[Utility Classes]

Static class that executes Snap2 searches. More...

Inheritance diagram for SnapSearch:

Inheritance graph
[legend]

List of all members.

Static Public Member Functions

static execute ($req, $mode=self::MODE_METADATA)
 Executes a search request.
static grep ($pattern, $domain= '//', $types=array(), $options=array(), $statuses=array())
 Searches for content using regular expressions.

Static Private Member Functions

static buildConstraints ($type, $constraints, $conj)
 Generates WHERE clause for search.
static buildSelect ($type, $domain, $mode)
 Builds the SELECT ... part of the search query.
static convertOp ($v, $op)
 Converts operators and values to proper SQL.


Detailed Description

Static class that executes Snap2 searches.

To use this class, create a SnapSearchRequest object, fill it with the search parameters and then call SnapSearch::execute() with the object to get the results. This class also supports grepping of content with regular expressions (SnapSearch::grep()).

Definition at line 12 of file SnapSearch.php5.


Member Function Documentation

static SnapSearch::buildConstraints ( type,
constraints,
conj 
) [static, private]

Generates WHERE clause for search.

For internal use only.

The WHERE clause is based on the constraints given and the types searched over

Parameters:
$type [string]: which type is being searched over
$constraints [array]: array of arrays, the inner arrays containing three elements:
  • [0] Operator: '=', '<', etc.
  • [1] Field: database attribute to compare
  • [2] Value: value to compare field to using operator
$conj [string]: one of SnapSearchRequest::CONJ_* constants
Returns:
[string]: WHERE clause

Definition at line 550 of file SnapSearch.php5.

static SnapSearch::buildSelect ( type,
domain,
mode 
) [static, private]

Builds the SELECT ... part of the search query.

For internal use only.

This does not include the FROM clause or any joins, just essentially the list of variables that need to be selected.

Parameters:
$type [int]: filesystem object type
$domain [string]: path prefix that describes where in the filesystem tree to filter the search results
$mode [int]: one of the MODE_* constants as given above (only MODE_LIST is checked)
Returns:
[string]: SELECT ... portion of search query

Definition at line 377 of file SnapSearch.php5.

static SnapSearch::convertOp ( v,
op 
) [static, private]

Converts operators and values to proper SQL.

For internal use only.

This method exists to translate SnapSearchRequest::OP_* constants to the appropriate SQL equivalent.

Parameters:
$v [mixed]: target value of operator
$op [int]: operator
Returns:
[string]: converted SQL

Definition at line 613 of file SnapSearch.php5.

static SnapSearch::execute ( req,
mode = self::MODE_METADATA 
) [static]

Executes a search request.

Build a SnapSearchRequest object first, and pass it to this method to get the results. You can get the results in several formats based on what you pass in the 2nd argument:

  • MODE_LIST: array of paths for each matching filesystem object, along with some additional information
  • MODE_METADATA: like MODE_LIST, but include the complete file metadata in the result array
  • MODE_ALL: same as MODE_METADATA, but include version content (which would otherwise be excluded)
  • MODE_OBJECTS: return Snap2 objects
  • MODE_ALL_OBJECTS: combines MODE_OBJECTS and MODE_ALL
Parameters:
$req [SnapSearchRequest]: request object that defines the search criteria
$mode [int]: one of the MODE_* constants as described above
Returns:
[mixed]: null on error, otherwise, depends on the value of $mode

Definition at line 40 of file SnapSearch.php5.

References SnapVersion::$ATTRIBUTES, SnapResource::$ATTRIBUTES, STimer::end(), STimer::endAvg(), SObject::getLastStaticError(), SnapDBI::query(), STimer::start(), and STimer::startAvg().

static SnapSearch::grep ( pattern,
domain = '//',
types = array(),
options = array(),
statuses = array() 
) [static]

Searches for content using regular expressions.

This method takes a pattern and some options and finds versions that have content that matches the regular expression pattern provided. The $options parameter is an array that may contain zero or more of the following constants:

  • GREP_CASE_INSENSITIVE: do a case-insensitive match (like the '/i' flag on regexes)
  • GREP_MULTILINE: makes '^' and '$' match beginning and end of line instead of beginning and end of string
  • GREP_MATCH_NEWLINE: makes '.' match newline characters (default is not to)
  • GREP_MATCH_ALL: include all matches from a version, not just that the version matched
If GREP_MATCH_ALL is not used, the method returns an array indexed by path for each matchin version. Each element of the array is two-element array, where the first element is the entire line (or set of lines) containing the match and the second element is just the matched portion of the line(s) itself.

If GREP_MATCH_ALL is used, the method returns an array indexed by path for each matching version. The value of each array is a sub-array that contains a list of two-element arrays, where the first element is the entire line (or set of lines) containing the match and the second element is just the portion of the line that matched.

Parameters:
$pattern [string]: regular expression pattern to match
$domain [string]: path to directory or resource under which to search versions for pattern
$types [array]: list of content types that should be searched (see SnapResource)
$options [array]: one of the GREP_* constants as described above
$statuses [array]: list of version statuses that should be searched (see SnapVersion)
Returns:
[array]: null on error, otherwise, arrays as described above

Definition at line 299 of file SnapSearch.php5.

References STimer::endAvg(), and STimer::startAvg().


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:06:30 2010 for Common by  doxygen 1.5.6