#include "CLucene/StdHeader.h" #ifndef _lucene_queryParser_QueryParser_ #define _lucene_queryParser_QueryParser_ #include "QueryParserConstants.h" #include "CLucene/analysis/AnalysisHeader.h" #include "CLucene/util/Reader.h" #include "CLucene/search/SearchHeader.h" #include "CLucene/index/Term.h" #include "TokenList.h" #include "QueryToken.h" #include "QueryParserBase.h" #include "Lexer.h" using namespace lucene::util; using namespace lucene::index; using namespace lucene::analysis; using namespace lucene::search; namespace lucene{ namespace queryParser{ //

It's a query parser. // The only method that clients should need to call is Parse(). // The syntax for query const char_t*s is as follows: // A Query is a series of clauses. A clause may be prefixed by:

// //

// A clause may be either:

// //

// Thus, in BNF, the query grammar is:

// // Query ::= ( Clause )* // Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" ) // //

// Examples of appropriately formatted queries can be found in the test cases. //

// class QueryParser : public QueryParserBase { private: Analyzer& analyzer; const char_t* field; TokenList* tokens; public: // Initializes a new instance of the QueryParser class with a specified field and // analyzer values. QueryParser(const char_t* _field, Analyzer& _analyzer); ~QueryParser(); // Returns a new instance of the QueryParser class with a specified query, field and // analyzer values. // The query to parse. // The default field for query terms. // Used to find terms in the query text. // static Query& Parse(const char_t* query, const char_t* field, Analyzer& analyzer); // Returns a parsed Query instance. // The query value to be parsed. // A parsed Query instance. Query& Parse(const char_t* query); // Returns a parsed Query instance. // The TextReader value to be parsed. // A parsed Query instance. Query& Parse(Reader& reader); private: // matches for CONJUNCTION // CONJUNCTION ::= | int_t MatchConjunction(); // matches for MODIFIER // MODIFIER ::= | | int_t MatchModifier(); // matches for QUERY // QUERY ::= [MODIFIER] CLAUSE ( [MODIFIER] CLAUSE)* Query* MatchQuery(const char_t* field); // matches for CLAUSE // CLAUSE ::= [TERM ] ( TERM | ( QUERY )) Query* MatchClause(const char_t* field); // matches for TERM // TERM ::= TERM | PREFIXTERM | WILDTERM | NUMBER // [ ] [ []] // // | ( | ) [ ] // | [SLOP] [ ] Query* MatchTerm(const char_t* field); // matches for QueryToken of the specified type and returns it // otherwise Exception throws QueryToken* MatchQueryToken(QueryTokenTypes expectedType); }; }} #endif