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


PHP Zend_Search_Lucene_Search_QueryParser::dontSuppressQueryParsingExceptions方法代码示例

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


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

示例1: testQueryParserExceptionsHandling

 public function testQueryParserExceptionsHandling()
 {
     $this->assertTrue(Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed());
     try {
         $query = Zend_Search_Lucene_Search_QueryParser::parse('contents:[business TO by}');
     } catch (Zend_Search_Lucene_Exception $e) {
         $this->fail('exception raised while parsing a query');
     }
     $this->assertEquals('contents business to by', $query->__toString());
     Zend_Search_Lucene_Search_QueryParser::dontSuppressQueryParsingExceptions();
     $this->assertFalse(Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed());
     try {
         $query = Zend_Search_Lucene_Search_QueryParser::parse('contents:[business TO by}');
         $this->fail('exception wasn\'t raised while parsing a query');
     } catch (Zend_Search_Lucene_Exception $e) {
         $this->assertEquals('Syntax error at char position 25.', $e->getMessage());
     }
     Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions();
     $this->assertTrue(Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed());
 }
开发者ID:ThorstenSuckow,项目名称:conjoon,代码行数:20,代码来源:Search23Test.php

示例2: search

 function search()
 {
     if (!empty($this->data['Tutorial'])) {
         // convert POST to Cake named params (it's prettier than GET)
         $this->redirect(array_merge($this->params['named'], $this->data['Tutorial']));
     }
     // default to boolean AND searching
     Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);
     $query = '';
     // Are there any parameters besides page?
     $named_params = array_diff_key($this->params['named'], array('page' => ''));
     if (!empty($named_params)) {
         // sanitize with exceptions for Zend Lucene query language. (Do the exceptions introduce a vulnerability?
         //   Can Zend Lucene validate a query ahead of time?)
         if (isset($this->params['named']['term'])) {
             //        $query = Sanitize::paranoid($this->params['named']['term'],
             //          array(' ', '"', "'", ':', '?', '*', '~', '[', ']', '_', '-', '{', '}', '.', '^', '+', '-', '(',
             //            ')', '&', '|', '!'));
             $query = $this->params['named']['term'];
             if (!empty($query)) {
                 // Intercept invalid queries
                 try {
                     Zend_Search_Lucene_Search_QueryParser::dontSuppressQueryParsingExceptions();
                     $parsed_query = Zend_Search_Lucene_Search_QueryParser::parse($query);
                 } catch (Zend_Search_Lucene_Exception $e) {
                     // Why can't I catch Zend_Search_Lucene_Search_QueryParserException?
                     $this->Session->setFlash("We're not sure what you mean. Are your search terms correct?");
                     $this->redirect(array('action' => 'search', 'term' => Sanitize::paranoid($query, array(" "))));
                 }
             }
         } else {
             $parsed_query = new Zend_Search_Lucene_Search_Query_Boolean();
         }
         try {
             if (isset($this->params['named']['learning_goal'])) {
                 $learning_goals = explode('|', $this->params['named']['learning_goal']);
                 foreach ($learning_goals as $learning_goal) {
                     if (is_numeric($learning_goal)) {
                         $learning_goal_term = new Zend_Search_Lucene_Index_Term($learning_goal, 'learning_goal');
                         $learning_goal_query = new Zend_Search_Lucene_Search_Query_Term($learning_goal_term);
                         $parsed_query->addSubquery($learning_goal_query, true);
                     }
                 }
             }
             if (isset($this->params['named']['resource_type'])) {
                 $resource_types = explode('|', $this->params['named']['resource_type']);
                 foreach ($resource_types as $resource_type) {
                     if (is_numeric($resource_type)) {
                         $resource_type_term = new Zend_Search_Lucene_Index_Term($resource_type, 'resource_type');
                         $resource_type_query = new Zend_Search_Lucene_Search_Query_Term($resource_type_term);
                         $parsed_query->addSubquery($resource_type_query, true);
                     }
                 }
             }
             if (isset($this->params['named']['keyword'])) {
                 $keywords = explode('|', $this->params['named']['keyword']);
                 foreach ($keywords as $keyword) {
                     if (preg_match('/[A-Za-z0-9\\-]+/', $keyword)) {
                         // valid UUID?
                         $keyword_term = new Zend_Search_Lucene_Index_Term($keyword, 'keyword');
                         $keyword_query = new Zend_Search_Lucene_Search_Query_Term($keyword_term);
                         $parsed_query->addSubquery($keyword_query, true);
                     }
                 }
             }
         } catch (Zend_Search_Lucene_Exception $e) {
             // Why can't I catch Zend_Search_Lucene_Search_QueryParserException?
             $this->Session->setFlash("We're not sure what you mean. Are your search terms correct?");
             $this->redirect(array('action' => 'search', 'query' => $query));
         }
         $this->paginate['SearchIndex'] = array('limit' => 10, 'conditions' => array('query' => $parsed_query), 'highlight' => true);
         $this->set('tutorials', $this->paginate($this->Tutorial->SearchIndex));
     } else {
         $this->paginate = array('published', 'limit' => 10, 'order' => 'Tutorial.title ASC', 'conditions' => array('in_index' => true), 'contain' => array('Tag'));
         $this->set('tutorials', $this->paginate($this->Tutorial));
     }
     $this->layout = 'institution';
     $results_context = array('model' => '', 'key' => '', 'id' => 0, 'name' => '');
     $this->set(compact('results_context'));
     $this->set('learningGoals', $this->Tutorial->LearningGoal->find('list'));
     $this->set('resourceTypes', $this->Tutorial->ResourceType->find('list'));
 }
开发者ID:nkuitse,项目名称:Guide-on-the-Side,代码行数:82,代码来源:TutorialsController.php


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