From: Kostka B. <ko...@to...> - 2015-01-23 15:22:10
|
Hello, I never used QueryParser::parse static method so I'm not sure, but if you pass a complex query as first parameter it should return correct Query object Please note this static method is marked /** For backward compatibility */ in source code, so better way is to create QueryParser object and call member parse(const TCHAR* _query) method. This avoid creation of new parser object for each query you parse so it is a bit more efficient. Borek From: norbert barichard [mailto:nor...@di...] Sent: Friday, January 23, 2015 2:31 PM To: clu...@li... Subject: [CLucene-dev] Parsing queries ? Hello, I would like to know if there is a way (in CLucene2.3.3.4) to build a Query* object from a complete Lucene query string, taking into account all of its operators (AND, OR, NOT, +, -, :, (), etc.). Until now, I've been able to use the QueryParser to build fairly simple queries, like this for example : /*******/ BooleanQuery* lBoolQuery = new BooleanQuery(); Query* lQuery1 = QueryParser::parse( _T( "sampleValue1" ), _T( "sampleField1" ), lAnalyzer ); Query* lQuery2 = QueryParser::parse( _T( "sampleValue2" ), _T( "sampleField2" ), lAnalyzer ); lBoolQuery ->add( lQuery1, true, BooleanClause::MUST ); lBoolQuery->add( lQuery2, true, BooleanClause::MUST ); /*******/ This works ok. But if I've got a complex Lucene string query, like : "title:(test -stuff) AND text:"hello wor*") OR "something nice"^4 ... How can I use this to get a Query* object representing this request ? I'm assuming there is a method to do that, I just can't find it. And I don't want to write a parser myself ! Thanks in advance, -- [cid:image001.png@01D03728.79E22E30] |