public static function parse($strQuery, $encoding = null)
    {
        self::_getInstance();

        // Reset FSM if previous parse operation didn't return it into a correct state
        self::$_instance->reset();

        include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
        try {
            include_once 'Zend/Search/Lucene/Search/QueryParserContext.php';

            self::$_instance->_encoding     = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding;
            self::$_instance->_lastToken    = null;
            self::$_instance->_context      = new Zend_Search_Lucene_Search_QueryParserContext(self::$_instance->_encoding);
            self::$_instance->_contextStack = array();
            self::$_instance->_tokens       = self::$_instance->_lexer->tokenize($strQuery, self::$_instance->_encoding);

            // Empty query
            if (count(self::$_instance->_tokens) == 0) {
                include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
                return new Zend_Search_Lucene_Search_Query_Insignificant();
            }


            foreach (self::$_instance->_tokens as $token) {
                try {
                    self::$_instance->_currentToken = $token;
                    self::$_instance->process($token->type);

                    self::$_instance->_lastToken = $token;
                } catch (Exception $e) {
                    if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
                        throw new Zend_Search_Lucene_Search_QueryParserException('Syntax error at char position ' . $token->position . '.', 0, $e);
                    }

                    include_once 'Zend/Search/Lucene/Exception.php';
                    throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
                }
            }

            if (count(self::$_instance->_contextStack) != 0) {
                throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.');
            }

            return self::$_instance->_context->getQuery();
        } catch (Zend_Search_Lucene_Search_QueryParserException $e) {
            if (self::$_instance->_suppressQueryParsingExceptions) {
                $queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding);

                include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
                $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
                $termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
                                                                                   null /* optional term */;

                include_once 'Zend/Search/Lucene/Index/Term.php';
                foreach ($queryTokens as $token) {
                    $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
                }


                return $query;
            } else {
                include_once 'Zend/Search/Lucene/Exception.php';
                throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
public static function parse($strQuery, $encoding = null)
    {
        self::_getInstance();

        // Reset FSM if previous parse operation didn't return it into a correct state
        self::$_instance->reset();

        include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
        try {
            include_once 'Zend/Search/Lucene/Search/QueryParserContext.php';

            self::$_instance->_encoding     = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding;
            self::$_instance->_lastToken    = null;
            self::$_instance->_context      = new Zend_Search_Lucene_Search_QueryParserContext(self::$_instance->_encoding);
            self::$_instance->_contextStack = array();
            self::$_instance->_tokens       = self::$_instance->_lexer->tokenize($strQuery, self::$_instance->_encoding);

            // Empty query
            if (count(self::$_instance->_tokens) == 0) {
                include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
                return new Zend_Search_Lucene_Search_Query_Insignificant();
            }


            foreach (self::$_instance->_tokens as $token) {
                try {
                    self::$_instance->_currentToken = $token;
                    self::$_instance->process($token->type);

                    self::$_instance->_lastToken = $token;
                } catch (Exception $e) {
                    if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
                        throw new Zend_Search_Lucene_Search_QueryParserException('Syntax error at char position ' . $token->position . '.', 0, $e);
                    }

                    include_once 'Zend/Search/Lucene/Exception.php';
                    throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
                }
            }

            if (count(self::$_instance->_contextStack) != 0) {
                throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.');
            }

            return self::$_instance->_context->getQuery();
        } catch (Zend_Search_Lucene_Search_QueryParserException $e) {
            if (self::$_instance->_suppressQueryParsingExceptions) {
                $queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding);

                include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
                $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
                $termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
                                                                                   null /* optional term */;

                include_once 'Zend/Search/Lucene/Index/Term.php';
                foreach ($queryTokens as $token) {
                    $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
                }


                return $query;
            } else {
                include_once 'Zend/Search/Lucene/Exception.php';
                throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
public static function parse ( $ strQuery , $ encoding = null ) { self :: _getInstance ( ) ; // Reset FSM if previous parse operation didn't return it into a correct state self :: $ _instance -> reset ( ) ; include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; try { include_once 'Zend/Search/Lucene/Search/QueryParserContext.php' ; self :: $ _instance -> _encoding = ( $ encoding !== null ) ? $ encoding : self :: $ _instance -> _defaultEncoding ; self :: $ _instance -> _lastToken = null ; self :: $ _instance -> _context = new Zend_Search_Lucene_Search_QueryParserContext ( self :: $ _instance -> _encoding ) ; self :: $ _instance -> _contextStack = array ( ) ; self :: $ _instance -> _tokens = self :: $ _instance -> _lexer -> tokenize ( $ strQuery , self :: $ _instance -> _encoding ) ; // Empty query if ( count ( self :: $ _instance -> _tokens ) == 0 ) { include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php' ; return new Zend_Search_Lucene_Search_Query_Insignificant ( ) ; } foreach ( self :: $ _instance -> _tokens as $ token ) { try { self :: $ _instance -> _currentToken = $ token ; self :: $ _instance -> process ( $ token -> type ) ; self :: $ _instance -> _lastToken = $ token ; } catch ( Exception $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'There is no any rule for' ) !== false ) { throw new Zend_Search_Lucene_Search_QueryParserException ( 'Syntax error at char position ' . $ token -> position . '.' , 0 , $ e ) ; } include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } if ( count ( self :: $ _instance -> _contextStack ) != 0 ) { throw new Zend_Search_Lucene_Search_QueryParserException ( 'Syntax Error: mismatched parentheses, every opening must have closing.' ) ; } return self :: $ _instance -> _context -> getQuery ( ) ; } catch ( Zend_Search_Lucene_Search_QueryParserException $ e ) { if ( self :: $ _instance -> _suppressQueryParsingExceptions ) { $ queryTokens = Zend_Search_Lucene_Analysis_Analyzer :: getDefault ( ) -> tokenize ( $ strQuery , self :: $ _instance -> _encoding ) ; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php' ; $ query = new Zend_Search_Lucene_Search_Query_MultiTerm ( ) ; $ termsSign = ( self :: $ _instance -> _defaultOperator == self :: B_AND ) ? true /* required term */ : null /* optional term */ ; include_once 'Zend/Search/Lucene/Index/Term.php' ; foreach ( $ queryTokens as $ token ) { $ query -> addTerm ( new Zend_Search_Lucene_Index_Term ( $ token -> getTermText ( ) ) , $ termsSign ) ; } return $ query ; } else { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } }
Parses a query string

@param  string $strQuery
@param  string $encoding
@return Zend_Search_Lucene_Search_Query
@throws Zend_Search_Lucene_Search_QueryParserException
Parses a query string