Lucene++ - a full-featured, c++ search engine
API Documentation


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
QueryParser.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
6 
7 #ifndef QUERYPARSER_H
8 #define QUERYPARSER_H
9 
10 #include "QueryParserConstants.h"
11 #include "DateTools.h"
12 #include "BooleanClause.h"
13 
14 namespace Lucene
15 {
17 
70  class LPPAPI QueryParser : public QueryParserConstants, public LuceneObject
71  {
72  public:
77  QueryParser(LuceneVersion::Version matchVersion, const String& field, AnalyzerPtr analyzer);
78 
81 
84 
85  virtual ~QueryParser();
86 
88 
90  enum Operator { OR_OPERATOR, AND_OPERATOR };
91 
92  protected:
93  static const int32_t CONJ_NONE;
94  static const int32_t CONJ_AND;
95  static const int32_t CONJ_OR;
96 
97  static const int32_t MOD_NONE;
98  static const int32_t MOD_NOT;
99  static const int32_t MOD_REQ;
100 
103 
105  int32_t _jj_ntk;
108 
109  int32_t jj_la;
110  int32_t jj_gen;
112 
113  static const int32_t jj_la1_0[];
114  static const int32_t jj_la1_1[];
115 
116  struct JJCalls;
117  typedef boost::shared_ptr<JJCalls> JJCallsPtr;
118 
119  struct JJCalls
120  {
122  {
123  gen = 0;
124  arg = 0;
125  }
126 
127  int32_t gen;
129  int32_t arg;
131  };
132 
134  bool jj_rescan;
135  int32_t jj_gc;
136 
139  int32_t jj_kind;
141  int32_t jj_endpos;
142 
143  public:
148 
150  String field;
151  int32_t phraseSlop;
152  double fuzzyMinSim;
154  std::locale locale;
155 
156  // the default date resolution
158 
159  // maps field names to date resolutions
161 
162  // The collator to use when determining range inclusion, for use when constructing RangeQuerys
164 
167 
170 
173 
174  public:
177  QueryPtr parse(const String& query);
178 
180  AnalyzerPtr getAnalyzer();
181 
183  String getField();
184 
186  double getFuzzyMinSim();
187 
189  void setFuzzyMinSim(double fuzzyMinSim);
190 
193  int32_t getFuzzyPrefixLength();
194 
197  void setFuzzyPrefixLength(int32_t fuzzyPrefixLength);
198 
201  void setPhraseSlop(int32_t phraseSlop);
202 
204  int32_t getPhraseSlop();
205 
210  void setAllowLeadingWildcard(bool allowLeadingWildcard);
211 
213  bool getAllowLeadingWildcard();
214 
220  void setEnablePositionIncrements(bool enable);
221 
223  bool getEnablePositionIncrements();
224 
230  void setDefaultOperator(Operator op);
231 
233  Operator getDefaultOperator();
234 
237  void setLowercaseExpandedTerms(bool lowercaseExpandedTerms);
238 
240  bool getLowercaseExpandedTerms();
241 
248  void setMultiTermRewriteMethod(RewriteMethodPtr method);
249 
251  RewriteMethodPtr getMultiTermRewriteMethod();
252 
254  void setLocale(std::locale locale);
255 
257  std::locale getLocale();
258 
263  void setDateResolution(DateTools::Resolution dateResolution);
264 
268  void setDateResolution(const String& fieldName, DateTools::Resolution dateResolution);
269 
272  DateTools::Resolution getDateResolution(const String& fieldName);
273 
280  void setRangeCollator(CollatorPtr rc);
281 
283  CollatorPtr getRangeCollator();
284 
286  static int main(Collection<String> args);
287 
290  int32_t Conjunction();
291  int32_t Modifiers();
292 
294  virtual QueryPtr TopLevelQuery(const String& field);
295 
296  virtual QueryPtr ParseQuery(const String& field);
297  virtual QueryPtr ParseClause(const String& field);
298  virtual QueryPtr ParseTerm(const String& field);
299 
301  virtual void ReInit(QueryParserCharStreamPtr stream);
302 
304  virtual void ReInit(QueryParserTokenManagerPtr tokenMgr);
305 
307  virtual QueryParserTokenPtr getNextToken();
308 
310  virtual QueryParserTokenPtr getToken(int32_t index);
311 
313  virtual void generateParseException();
314 
316  virtual void enable_tracing();
317 
319  virtual void disable_tracing();
320 
321  protected:
323  void ConstructParser(QueryParserCharStreamPtr stream, QueryParserTokenManagerPtr tokenMgr);
324 
325  virtual void addClause(Collection<BooleanClausePtr> clauses, int32_t conj, int32_t mods, QueryPtr q);
326 
329  virtual QueryPtr getFieldQuery(const String& field, const String& queryText);
330 
333  virtual QueryPtr getFieldQuery(const String& field, const String& queryText, int32_t slop);
334 
336  virtual QueryPtr getRangeQuery(const String& field, const String& part1, const String& part2, bool inclusive);
337 
340  BooleanQueryPtr newBooleanQuery(bool disableCoord);
341 
346  BooleanClausePtr newBooleanClause(QueryPtr q, BooleanClause::Occur occur);
347 
351  QueryPtr newTermQuery(TermPtr term);
352 
355  PhraseQueryPtr newPhraseQuery();
356 
359  MultiPhraseQueryPtr newMultiPhraseQuery();
360 
364  QueryPtr newPrefixQuery(TermPtr prefix);
365 
371  QueryPtr newFuzzyQuery(TermPtr term, double minimumSimilarity, int32_t prefixLength);
372 
379  QueryPtr newRangeQuery(const String& field, const String& part1, const String& part2, bool inclusive);
380 
383  QueryPtr newMatchAllDocsQuery();
384 
388  QueryPtr newWildcardQuery(TermPtr term);
389 
397  virtual QueryPtr getBooleanQuery(Collection<BooleanClausePtr> clauses);
398 
407  virtual QueryPtr getBooleanQuery(Collection<BooleanClausePtr> clauses, bool disableCoord);
408 
424  virtual QueryPtr getWildcardQuery(const String& field, const String& termStr);
425 
440  virtual QueryPtr getPrefixQuery(const String& field, const String& termStr);
441 
448  virtual QueryPtr getFuzzyQuery(const String& field, const String& termStr, double minSimilarity);
449 
452  String discardEscapeChar(const String& input);
453 
455  static int32_t hexToInt(wchar_t c);
456 
459  static String escape(const String& s);
460 
461  bool jj_2_1(int32_t xla);
462  bool jj_3R_2();
463  bool jj_3_1();
464  bool jj_3R_3();
465 
466  QueryParserTokenPtr jj_consume_token(int32_t kind);
467  bool jj_scan_token(int32_t kind);
468  int32_t jj_ntk();
469  void jj_add_error_token(int32_t kind, int32_t pos);
470  void jj_rescan_token();
471  void jj_save(int32_t index, int32_t xla);
472  };
473 }
474 
475 #endif

clucene.sourceforge.net