CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_queryParser_QueryParser_ 00008 #define _lucene_queryParser_QueryParser_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/analysis/AnalysisHeader.h" 00015 #include "CLucene/util/Reader.h" 00016 #include "CLucene/search/SearchHeader.h" 00017 #include "CLucene/index/Term.h" 00018 00019 #include "TokenList.h" 00020 #include "QueryToken.h" 00021 #include "QueryParserBase.h" 00022 #include "Lexer.h" 00023 00024 CL_NS_DEF(queryParser) 00025 00026 00056 class QueryParser : public QueryParserBase 00057 { 00058 private: 00059 const TCHAR* field; 00060 TokenList* tokens; 00061 public: 00066 QueryParser(const TCHAR* field, CL_NS(analysis)::Analyzer* analyzer); 00067 ~QueryParser(); 00068 00075 virtual CL_NS(search)::Query* parse(const TCHAR* query); 00076 00083 virtual CL_NS(search)::Query* parse(CL_NS(util)::Reader* reader); 00084 00089 static CL_NS(search)::Query* parse(const TCHAR* query, const TCHAR* field, CL_NS(analysis)::Analyzer* analyzer); 00090 00091 CL_NS(analysis)::Analyzer* getAnalyzer() { return analyzer; } 00092 00096 const TCHAR* getField() { return field; } 00097 00098 //deprecated functions 00099 _CL_DEPRECATED( setLowercaseExpandedTerms ) void setLowercaseWildcardTerms(bool lowercaseWildcardTerms){ setLowercaseExpandedTerms(lowercaseWildcardTerms); } 00100 _CL_DEPRECATED( getLowercaseExpandedTerms ) bool getLowercaseWildcardTerms() const { return getLowercaseExpandedTerms(); } 00101 protected: 00102 //these functions may be defined under certain compilation conditions. 00103 //note that this functionality is deprecated, you should create your own queryparser 00104 //if you want to remove this functionality...it will be removed... be warned! 00105 #ifdef NO_PREFIX_QUERY 00106 virtual CL_NS(search)::Query* GetPrefixQuery(const TCHAR* field,const TCHAR* termStr){ return NULL; } 00107 #endif 00108 #ifdef NO_FUZZY_QUERY 00109 virtual CL_NS(search)::Query* GetFuzzyQuery(const TCHAR* field,const TCHAR* termStr){ return NULL; } 00110 #endif 00111 #ifdef NO_RANGE_QUERY 00112 virtual CL_NS(search)::Query* GetRangeQuery(const TCHAR* field, const TCHAR* part1, const TCHAR* part2, bool inclusive) { return NULL; } 00113 #endif 00114 #ifdef NO_WILDCARD_QUERY 00115 virtual CL_NS(search)::Query* GetWildcardQuery(const TCHAR* field, TCHAR* termStr) { return NULL; } 00116 #endif 00117 private: 00122 int32_t MatchConjunction(); 00123 00128 int32_t MatchModifier(); 00129 00134 CL_NS(search)::Query* MatchQuery(const TCHAR* field); 00135 00140 CL_NS(search)::Query* MatchClause(const TCHAR* field); 00141 00150 CL_NS(search)::Query* MatchTerm(const TCHAR* field); 00151 00156 QueryToken* MatchQueryToken(QueryToken::Types expectedType); 00157 00162 void ExtractAndDeleteToken(void); 00163 }; 00164 CL_NS_END 00165 #endif