Search/Lucene/Search/QueryParser.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.

Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Search_Lucene  
Subpackage
Search  
Version
$Id: QueryParser.php 24593 2012-01-05 20:35:02Z matthew $  

\Zend_Search_Lucene_Search_QueryParser

Package: Zend\Search\Lucene\Search
Abstract Finite State Machine

Take a look on Wikipedia state machine description: http://en.wikipedia.org/wiki/Finite_state_machine

Any type of Transducers (Moore machine or Mealy machine) also may be implemented by using this abstract FSM. process() methods invokes a specified actions which may construct FSM output. Actions may be also used to signal, that we have reached Accept State

Parent(s)
\Zend_Search_Lucene_FSM
Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Constants

>VConstant  B_OR = 0
Boolean operators constants
>VConstant  B_AND = 1
>VConstant  ST_COMMON_QUERY_ELEMENT = 0
Query parser State Machine states
>VConstant  ST_CLOSEDINT_RQ_START = 1
>VConstant  ST_CLOSEDINT_RQ_FIRST_TERM = 2
>VConstant  ST_CLOSEDINT_RQ_TO_TERM = 3
>VConstant  ST_CLOSEDINT_RQ_LAST_TERM = 4
>VConstant  ST_CLOSEDINT_RQ_END = 5
>VConstant  ST_OPENEDINT_RQ_START = 6
>VConstant  ST_OPENEDINT_RQ_FIRST_TERM = 7
>VConstant  ST_OPENEDINT_RQ_TO_TERM = 8
>VConstant  ST_OPENEDINT_RQ_LAST_TERM = 9
>VConstant  ST_OPENEDINT_RQ_END = 10

Properties

>VPropertyprivate\Zend_Search_Lucene_Search_QueryParserContext $_context
Current query parser context
>VPropertyprivatearray $_contextStack
Context stack
Details
Type
array
>VPropertyprivateinteger|string $_currentState = null
inherited
Current state
Inherited from: \Zend_Search_Lucene_FSM::$$_currentState
Default valuenullDetails
Type
integer | string
Inherited_from
\Zend_Search_Lucene_FSM::$$_currentState  
>VPropertyprivateinteger|string $_currentToken
Current token
Details
Type
integer | string
>VPropertyprivatestring $_defaultEncoding = ''
Query string default encoding
Default value''Details
Type
string
>VPropertyprivateinteger $_defaultOperator = self::B_OR
Default boolean queries operator
Default valueself::B_ORDetails
Type
integer
>VPropertyprivatestring $_encoding
Query string encoding
Details
Type
string
>VPropertyprivatearray $_entryActions = array()
inherited
List of entry actions Each action executes when entering the state
Inherited from: \Zend_Search_Lucene_FSM::$$_entryActions

[state] => action

Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_entryActions  
>VPropertyprivatearray $_exitActions = array()
inherited
List of exit actions Each action executes when exiting the state
Inherited from: \Zend_Search_Lucene_FSM::$$_exitActions

[state] => action

Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_exitActions  
>VPropertyprivatearray $_inputActions = array()
inherited
List of input actions Each action executes when entering the state
Inherited from: \Zend_Search_Lucene_FSM::$$_inputActions

[state][input] => action

Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_inputActions  
>VPropertyprivatearray $_inputAphabet = array()
inherited
Input alphabet
Inherited from: \Zend_Search_Lucene_FSM::$$_inputAphabet
Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_inputAphabet  
>VPropertyprivate\Zend_Search_Lucene_Search_QueryParser $_instance = null
static
Parser instance
Default valuenullDetails
Type
\Zend_Search_Lucene_Search_QueryParser
>VPropertyprivate\Zend_Search_Lucene_Search_QueryToken $_lastToken = null
Last token

It can be processed within FSM states, but this addirional state simplifies FSM

Default valuenullDetails
Type
\Zend_Search_Lucene_Search_QueryToken
>VPropertyprivate\Zend_Search_Lucene_Search_QueryLexer $_lexer
Query lexer
>VPropertyprivatestring $_rqFirstTerm = null
Range query first term
Default valuenullDetails
Type
string
>VPropertyprivatearray $_rules = array()
inherited
State transition table
Inherited from: \Zend_Search_Lucene_FSM::$$_rules

[sourceState][input] => targetState

Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_rules  
>VPropertyprivatearray $_states = array()
inherited
Machine States alphabet
Inherited from: \Zend_Search_Lucene_FSM::$$_states
Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_states  
>VPropertyprivateboolean $_suppressQueryParsingExceptions = true
Defines query parsing mode.

If this option is turned on, then query parser suppress query parser exceptions and constructs multi-term query using all words from a query.

That helps to avoid exceptions caused by queries, which don't conform to query language, but limits possibilities to check, that query entered by user has some inconsistencies.

Default is true.

Use Zend_Search_Lucene::suppressQueryParsingExceptions(), Zend_Search_Lucene::dontSuppressQueryParsingExceptions() and Zend_Search_Lucene::checkQueryParsingExceptionsSuppressMode() to operate with this setting.

Default valuetrueDetails
Type
boolean
>VPropertyprivatearray $_tokens
Tokens list Array of Zend_Search_Lucene_Search_QueryToken objects
Details
Type
array
>VPropertyprivatearray $_transitionActions = array()
inherited
List of input actions Each action executes when entering the state
Inherited from: \Zend_Search_Lucene_FSM::$$_transitionActions

[state1][state2] => action

Default valuearray()Details
Type
array
Inherited_from
\Zend_Search_Lucene_FSM::$$_transitionActions  

Methods

methodpublic__construct() : void

Parser constructor

$states is an array of integers or strings with a list of possible machine states constructor treats fist list element as a sturt state (assignes it to $_current state). It may be reassigned by setState() call. States list may be empty and can be extended later by addState() or addStates() calls.

$inputAphabet is the same as $states, but represents input alphabet it also may be extended later by addInputSymbols() or addInputSymbol() calls.

$rules parameter describes FSM transitions and has a structure: array( array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), ... ) Rules also can be added later by addRules() and addRule() calls.

FSM actions are very flexible and may be defined by addEntryAction(), addExitAction(), addInputAction() and addTransitionAction() calls.

methodprivate_getInstance() : \Zend_Search_Lucene_Search_QueryParser
static

Get query parser instance

methodpublicaddEntryAction(integer | string $state, \Zend_Search_Lucene_FSMAction $action) : void
inherited

Add state entry action.

Inherited from: \Zend_Search_Lucene_FSM::addEntryAction()

Several entry actions are allowed. Action execution order is defined by addEntryAction() calls

Parameters
NameTypeDescription
$stateinteger | string
$action\Zend_Search_Lucene_FSMAction
methodpublicaddExitAction(integer | string $state, \Zend_Search_Lucene_FSMAction $action) : void
inherited

Add state exit action.

Inherited from: \Zend_Search_Lucene_FSM::addExitAction()

Several exit actions are allowed. Action execution order is defined by addEntryAction() calls

Parameters
NameTypeDescription
$stateinteger | string
$action\Zend_Search_Lucene_FSMAction
methodpublicaddInputAction(integer | string $state,  $inputSymbol, \Zend_Search_Lucene_FSMAction $action) : void
inherited

Add input action (defined by {state, input} pair).

Inherited from: \Zend_Search_Lucene_FSM::addInputAction()

Several input actions are allowed. Action execution order is defined by addInputAction() calls

Parameters
NameTypeDescription
$stateinteger | string
$inputSymbol
$action\Zend_Search_Lucene_FSMAction
methodpublicaddInputSymbol(integer | string $inputSymbol) : void
inherited

Add symbol to the input alphabet

Inherited from: \Zend_Search_Lucene_FSM::addInputSymbol()
Parameters
NameTypeDescription
$inputSymbolinteger | string
methodpublicaddInputSymbols(array $inputAphabet) : void
inherited

Add symbols to the input alphabet

Inherited from: \Zend_Search_Lucene_FSM::addInputSymbols()
Parameters
NameTypeDescription
$inputAphabetarray
methodpublicaddPhraseEntry() : void

Add phrase to a query

methodpublicaddRule(integer | string $sourceState, integer | string $input, integer | string $targetState, \Zend_Search_Lucene_FSMAction | null $inputAction = null) : void
inherited

Add symbol to the input alphabet

Inherited from: \Zend_Search_Lucene_FSM::addRule()
Parameters
NameTypeDescription
$sourceStateinteger | string
$inputinteger | string
$targetStateinteger | string
$inputAction\Zend_Search_Lucene_FSMAction | null
Throws
ExceptionDescription
\Zend_Search_Exception
methodpublicaddRules(array $rules) : void
inherited

Add transition rules

Inherited from: \Zend_Search_Lucene_FSM::addRules()

array structure: array( array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), ... )

Parameters
NameTypeDescription
$rulesarray
methodpublicaddState(integer | string $state) : void
inherited

Add state to the state machine

Inherited from: \Zend_Search_Lucene_FSM::addState()
Parameters
NameTypeDescription
$stateinteger | string
methodpublicaddStates(array $states) : void
inherited

Add states to the state machine

Inherited from: \Zend_Search_Lucene_FSM::addStates()
Parameters
NameTypeDescription
$statesarray
methodpublicaddTermEntry() : void

Add term to a query

methodpublicaddTransitionAction(integer | string $sourceState, integer | string $targetState, \Zend_Search_Lucene_FSMAction $action) : void
inherited

Add transition action (defined by {state, input} pair).

Inherited from: \Zend_Search_Lucene_FSM::addTransitionAction()

Several transition actions are allowed. Action execution order is defined by addTransitionAction() calls

Parameters
NameTypeDescription
$sourceStateinteger | string
$targetStateinteger | string
$action\Zend_Search_Lucene_FSMAction
methodpublicclosedRQFirstTerm() : void

Process first range query term (closed interval)

methodpublicclosedRQLastTerm() : void

Process last range query term (closed interval)

methodpublicdontSuppressQueryParsingExceptions() : void
static

Turn off 'suppress query parser exceptions' mode.

methodpublicescape(string $keyword) : string
static

Escape keyword to force it to be parsed as one term

Parameters
NameTypeDescription
$keywordstring
Returns
TypeDescription
string
methodpublicgetDefaultEncoding() : string
static

Get query string default encoding

Returns
TypeDescription
string
methodpublicgetDefaultOperator() : integer
static

Get default boolean operator

Returns
TypeDescription
integer
methodpublicgetState() : integer | string
inherited

Get FSM state.

Inherited from: \Zend_Search_Lucene_FSM::getState()
Returns
TypeDescription
integer | string$state|null
methodpubliclogicalOperator() : void

Process logical operator

methodpublicopenedRQFirstTerm() : void

Process first range query term (opened interval)

methodpublicopenedRQLastTerm() : void

Process last range query term (opened interval)

methodpublicparse(string $strQuery, string $encoding = null) : \Zend_Search_Lucene_Search_Query
static

Parses a query string

Parameters
NameTypeDescription
$strQuerystring
$encodingstring
Returns
TypeDescription
\Zend_Search_Lucene_Search_Query
Throws
ExceptionDescription
\Zend_Search_Lucene_Search_QueryParserException
methodpublicprocess(mixed $input) : void
inherited

Process an input

Inherited from: \Zend_Search_Lucene_FSM::process()
Parameters
NameTypeDescription
$inputmixed
Throws
ExceptionDescription
\Zend_Search_Exception
methodpublicprocessFuzzyProximityModifier() : void

Process fuzzy search/proximity modifier - '~'

methodpublicprocessModifierParameter() : void

Process modifier parameter

Throws
ExceptionDescription
\Zend_Search_Lucene_Exception
methodpublicqueryParsingExceptionsSuppressed() : boolean
static

Check 'suppress query parser exceptions' mode.

Returns
TypeDescription
boolean
methodpublicreset() : void
inherited

Inherited from: \Zend_Search_Lucene_FSM::reset()
methodpublicsetDefaultEncoding(string $encoding) : void
static

Set query string default encoding

Parameters
NameTypeDescription
$encodingstring
methodpublicsetDefaultOperator(integer $operator) : void
static

Set default boolean operator

Parameters
NameTypeDescription
$operatorinteger
methodpublicsetField() : void

Set entry field

methodpublicsetSign() : void

Set entry sign

methodpublicsetState(integer | string $state) : void
inherited

Set FSM state.

Inherited from: \Zend_Search_Lucene_FSM::setState()

No any action is invoked

Parameters
NameTypeDescription
$stateinteger | string
Throws
ExceptionDescription
\Zend_Search_Exception
methodpublicsubqueryEnd() : void

End subquery

methodpublicsubqueryStart() : void

Start subquery

methodpublicsuppressQueryParsingExceptions() : void
static

Turn on 'suppress query parser exceptions' mode.

Documentation was generated by phpDocumentor 2.0.0a12.