当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Search_Lucene_Search_QueryParser::process方法代码示例

本文整理汇总了PHP中Zend_Search_Lucene_Search_QueryParser::process方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_QueryParser::process方法的具体用法?PHP Zend_Search_Lucene_Search_QueryParser::process怎么用?PHP Zend_Search_Lucene_Search_QueryParser::process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Search_Lucene_Search_QueryParser的用法示例。


在下文中一共展示了Zend_Search_Lucene_Search_QueryParser::process方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * Parses a query string
  *
  * @param string $strQuery
  * @param string $encoding
  * @return Zend_Search_Lucene_Search_Query
  * @throws Zend_Search_Lucene_Search_QueryParserException
  */
 public static function parse($strQuery, $encoding = null)
 {
     if (self::$_instance === null) {
         self::$_instance = new Zend_Search_Lucene_Search_QueryParser();
     }
     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) {
         return new Zend_Search_Lucene_Search_Query_Empty();
     }
     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 . '.');
             }
             throw $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();
 }
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:39,代码来源:QueryParser.php

示例2: parse

    /**
     * Parses a query string
     *
     * @param string $strQuery
     * @param string $encoding
     * @return Zend_Search_Lucene_Search_Query
     * @throws Zend_Search_Lucene_Search_QueryParserException
     */
    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();

        require_once 'Zend/Search/Lucene/Search/QueryParserException.php';
        try {
            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) {
                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 . '.' );
                    }

                    throw $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);

                $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
                $termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
                                                                                   null /* optional term */;

                foreach ($queryTokens as $token) {
                    $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
                }


                return $query;
            } else {
                throw $e;
            }
        }
    }
开发者ID:realfluid,项目名称:umbaugh,代码行数:68,代码来源:QueryParser.php


注:本文中的Zend_Search_Lucene_Search_QueryParser::process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。