PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Query Parser Exceptions

The query parser may generate two types of exceptions:

  • Zend_Search_Lucene_Exception is thrown if something goes wrong in the query parser itself.

  • Zend_Search_Lucene_Search_QueryParserException is thrown when there is an error in the query syntax.

It's a good idea to catch Zend_Search_Lucene_Search_QueryParserExceptions and handle them appropriately:

<?php
try {
    
$query Zend_Search_Lucene_Search_QueryParser::parse($queryString);
} catch (
Zend_Search_Lucene_Search_QueryParserException $e) {
    echo 
"Query syntax error: " $e->getMessage() . "\n";
}

The same technique should be used for the find() method of a Zend_Search_Lucene object.

Starting in 1.5, query parsing exceptions are suppressed by default. If query doesn't conform query language, then it's tokenized using current default analyzer and all tokenized terms are used for searching. Use Zend_Search_Lucene_Search_QueryParser::dontSuppressQueryParsingExceptions() method to turn exceptions on. Zend_Search_Lucene_Search_QueryParser::suppressQueryParsingExceptions() and Zend_Search_Lucene_Search_QueryParser::queryParsingExceptionsSuppressed() methods are also intended to manage exceptions handling behavior.

Zend Framework