Hi Jack, Query parser throws Zend_Search_Lucene_Search_QueryParserException exception if query doesn't conform query language. If it happens you can tokenize query using current analyzer and treat as a "set of words to search".
I agree that it would be good to provide something ready to use for this use case. Just created an issue for this (http://framework.zend.com/issues/browse/ZF-2099). Before it's done you can use something like this: ------------------------------------------------------- try { $hits = $index->find(($query); } catch (Zend_Search_Lucene_Search_QueryParserException $e) { $tokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($query, $encoding); if (Zend_Search_Lucene_Search_QueryParser::getDefaultOperator() == Zend_Search_Lucene_Search_QueryParser::B_AND) { $allTermsRequired = true; } else { $allTermsRequired = false; } $simplifiedQuery = new Zend_Search_Lucene_Search_Query_MultiTerm(); foreach ($tokens as $token) { $term = new Zend_Search_Lucene_Index_Term($token); $simplifiedQuery->addTerm($term, $allTermsRequired ? true:null); } $hits = $index->find(($simplifiedQuery); } ------------------------------------------- With best regards, Alexander Veremyev. > -----Original Message----- > From: Jack Sleight [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 24, 2007 8:21 PM > To: [email protected] > Subject: RE: [fw-general] Zend_Search_Lucene syntax error > exception when searching on "to" > > > Hi, > I don't really get this. I've just run into this same > problem, but after a discussion in the zftalk IRC channel it > seems searching for "foo to bar" > works for other people without an error? > > I had assumed there would be a way to throw any query string > possible at Zend_Search_Lucene_Search_QueryParser::parse and > it would make the best of it, without error. > > I mean, one of the most common uses of a search component is > to just have a simple text input search box on a page. Given > that anything could be typed into that, it should accept it. > You can't expect users to learn how to format search strings > correctly, nor can you just throw an error at them when they > typed something that usually has special meaning. > > Am I mistaken? Is there a way to do this? And why does it > seem to work for some people but not me? > Thanks in advance, > Jack > > > Alexander Veremyev wrote: > > > > Hi! > > > > That's correct. > > 'to' word is a part of the syntax, so it could be used only within a > > phrase: > > > > $index->find("\"out to lunch\""); > > > > > > You can also take reserved words into double-quotes to > escape them from > > interpretation as a part of syntax: > > > > $index->find('out "to" lunch'); > > > > > > I am not sure what is the best way for user friendly searching... > > I think, good idea is to parse query before searching and make some > > transformations if exception is thrown: > > > > ------------------------------------------ > > try { > > $parsedQuery = > Zend_Search_Lucene_Search_QueryParser::parse($query); > > } catch (Zend_Search_Lucene_Search_QueryParserException $e) { > > ... > > $parsedQuery = > > Zend_Search_Lucene_Search_QueryParser::parse($modifiedQuery); > > } > > > > $hits = $index->find($parsedQuery); > > > > > > PS Wildcard queries support is done now. You cant take it > with an SVN > > version or any of the latest snapshots. > > > > With best regards, > > Alexander Veremyev. > > > > -- > View this message in context: > http://www.nabble.com/Zend_Search_Lucene-syntax-error-exceptio > n-when-searching-on-%22to%22-tf4349915s16154.html#a13385744 > Sent from the Zend Framework mailing list archive at Nabble.com. > > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.503 / Virus Database: 269.15.8/1089 - Release > Date: 23.10.2007 19:39 > > No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.503 / Virus Database: 269.15.10/1091 - Release Date: 24.10.2007 14:31
