本文整理汇总了PHP中Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions方法的具体用法?PHP Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions怎么用?PHP Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Search_Lucene_Search_QueryParser
的用法示例。
在下文中一共展示了Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions方法的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());
}
示例2: get_lucene_query
/**
* Трансформация запроса nc_search_query в запрос Lucene
* @param nc_search_query $query
* @return Zend_Search_Lucene_Search_Query
*/
protected function get_lucene_query(nc_search_query $query)
{
Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions();
if ($this->get_setting('DefaultBooleanOperator') == 'AND') {
Zend_Search_Lucene_Search_QueryParser::setDefaultOperator(Zend_Search_Lucene_Search_QueryParser::B_AND);
}
$query_string = $query->to_string();
// range search for integers
if (nc_search::should('AllowRangeSearch') && strpos($query_string, ' TO ')) {
preg_match_all("/(\\[|\\{)\\s*(\\d+)\\s+TO\\s+(\\d+)\\s*(\\]|\\})/", $query_string, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$query_string = str_replace($m[0], $m[1] . $this->pad_integer($m[2]) . " TO " . $this->pad_integer($m[3]) . $m[4], $query_string);
}
}
// add a time range should it be required
$modified_after = $query->get('modified_after');
$modified_before = $query->get('modified_before');
if ($modified_before || $modified_after) {
$modified_after = $modified_after ? strftime("%Y%m%d%H%M%S", strtotime($modified_after)) : "19000101000000";
$modified_before = $modified_before ? strftime("%Y%m%d%H%M%S", strtotime($modified_before)) : "22000101000000";
$query_string = "({$query_string}) last_modified:[{$modified_after} TO {$modified_before}]";
}
// add area
$area = $query->get('area');
if ($area) {
if (!$area instanceof nc_search_area) {
$area = new nc_search_area($area);
}
$is_boolean = nc_search_util::is_boolean_query($query_string);
$query_string = "({$query_string}) " . ($is_boolean ? " AND " : "+") . $area->get_field_condition($is_boolean);
}
// parse string into Lucene Query
$zend_query = Zend_Search_Lucene_Search_QueryParser::parse($query_string, 'UTF-8');
return $zend_query;
}