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_QueryParserBase_ 00008 #define _lucene_queryParser_QueryParserBase_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/util/VoidList.h" 00015 #include "CLucene/search/BooleanClause.h" 00016 #include "CLucene/analysis/Analyzers.h" 00017 #include "QueryToken.h" 00018 00019 CL_NS_DEF(queryParser) 00020 00021 00025 class QueryParserBase:LUCENE_BASE 00026 { 00027 protected: 00028 /* The actual operator the parser uses to combine query terms */ 00029 int defaultOperator; 00030 int32_t phraseSlop; 00031 00032 bool lowercaseExpandedTerms; 00033 00034 LUCENE_STATIC_CONSTANT(int, CONJ_NONE=0); 00035 LUCENE_STATIC_CONSTANT(int, CONJ_AND=1); 00036 LUCENE_STATIC_CONSTANT(int, CONJ_OR=2); 00037 00038 LUCENE_STATIC_CONSTANT(int, MOD_NONE=0); 00039 LUCENE_STATIC_CONSTANT(int, MOD_NOT=10); 00040 LUCENE_STATIC_CONSTANT(int, MOD_REQ=11); 00041 00042 CL_NS(analysis)::Analyzer* analyzer; 00043 00044 public: 00045 QueryParserBase(CL_NS(analysis)::Analyzer* analyzer); 00046 ~QueryParserBase(); 00047 00052 void setLowercaseExpandedTerms(bool lowercaseExpandedTerms); 00053 00057 bool getLowercaseExpandedTerms() const; 00058 00059 //values used for setOperator 00060 LUCENE_STATIC_CONSTANT(int, OR_OPERATOR=0); 00061 LUCENE_STATIC_CONSTANT(int, AND_OPERATOR=1); 00062 00071 void setDefaultOperator(int oper); 00076 int getDefaultOperator() const; 00077 00078 //public so that the lexer can call this 00079 virtual void throwParserException(const TCHAR* message, TCHAR ch, int32_t col, int32_t line ); 00080 00085 void setPhraseSlop(int phraseSlop) { this->phraseSlop = phraseSlop; } 00086 00090 int getPhraseSlop() { return phraseSlop; } 00091 00092 protected: 00093 00097 void discardEscapeChar(TCHAR* token) const; 00098 00099 //Analyzes the expanded term termStr with the StandardFilter and the LowerCaseFilter. 00100 TCHAR* AnalyzeExpandedTerm(const TCHAR* field, TCHAR* termStr); 00101 00102 // Adds the next parsed clause. 00103 virtual void AddClause(std::vector<CL_NS(search)::BooleanClause*>& clauses, int32_t conj, int32_t mods, CL_NS(search)::Query* q); 00104 00110 virtual CL_NS(search)::Query* GetFieldQuery(const TCHAR* field, TCHAR* queryText); 00111 00116 virtual CL_NS(search)::Query* GetFieldQuery(const TCHAR* field, TCHAR* queryText, int32_t slop); 00117 00141 virtual CL_NS(search)::Query* GetPrefixQuery(const TCHAR* field, TCHAR* termStr); 00142 00164 virtual CL_NS(search)::Query* GetWildcardQuery(const TCHAR* field, TCHAR* termStr); 00165 00177 virtual CL_NS(search)::Query* GetFuzzyQuery(const TCHAR* field, TCHAR* termStr); 00178 00194 virtual CL_NS(search)::Query* GetBooleanQuery(std::vector<CL_NS(search)::BooleanClause*>& clauses); 00195 00199 virtual CL_NS(search)::Query* GetRangeQuery(const TCHAR* field, TCHAR* part1, TCHAR* part2, bool inclusive); 00200 virtual CL_NS(search)::Query* ParseRangeQuery(const TCHAR* field, TCHAR* str, bool inclusive); 00201 00202 }; 00203 CL_NS_END 00204 #endif