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 
2 // Copyright (c) 2009-2014 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 public:
76  QueryParser(LuceneVersion::Version matchVersion, const String& field, const AnalyzerPtr& analyzer);
77 
80 
82  QueryParser(const QueryParserTokenManagerPtr& tokenMgr);
83 
84  virtual ~QueryParser();
85 
87 
89  enum Operator { OR_OPERATOR, AND_OPERATOR };
90 
91 protected:
92  static const int32_t CONJ_NONE;
93  static const int32_t CONJ_AND;
94  static const int32_t CONJ_OR;
95 
96  static const int32_t MOD_NONE;
97  static const int32_t MOD_NOT;
98  static const int32_t MOD_REQ;
99 
102 
104  int32_t _jj_ntk;
107 
108  int32_t jj_la;
109  int32_t jj_gen;
111 
112  static const int32_t jj_la1_0[];
113  static const int32_t jj_la1_1[];
114 
115  struct JJCalls;
116  typedef boost::shared_ptr<JJCalls> JJCallsPtr;
117 
118  struct JJCalls {
120  gen = 0;
121  arg = 0;
122  }
123 
124  int32_t gen;
126  int32_t arg;
128  };
129 
131  bool jj_rescan;
132  int32_t jj_gc;
133 
136  int32_t jj_kind;
138  int32_t jj_endpos;
139 
140 public:
145 
147  String field;
148  int32_t phraseSlop;
149  double fuzzyMinSim;
151  std::locale locale;
152 
153  // the default date resolution
155 
156  // maps field names to date resolutions
158 
159  // The collator to use when determining range inclusion, for use when constructing RangeQuerys
161 
164 
167 
170 
171 public:
174  QueryPtr parse(const String& query);
175 
177  AnalyzerPtr getAnalyzer();
178 
180  String getField();
181 
183  double getFuzzyMinSim();
184 
186  void setFuzzyMinSim(double fuzzyMinSim);
187 
190  int32_t getFuzzyPrefixLength();
191 
194  void setFuzzyPrefixLength(int32_t fuzzyPrefixLength);
195 
198  void setPhraseSlop(int32_t phraseSlop);
199 
201  int32_t getPhraseSlop();
202 
207  void setAllowLeadingWildcard(bool allowLeadingWildcard);
208 
210  bool getAllowLeadingWildcard();
211 
217  void setEnablePositionIncrements(bool enable);
218 
220  bool getEnablePositionIncrements();
221 
227  void setDefaultOperator(Operator op);
228 
230  Operator getDefaultOperator();
231 
234  void setLowercaseExpandedTerms(bool lowercaseExpandedTerms);
235 
237  bool getLowercaseExpandedTerms();
238 
245  void setMultiTermRewriteMethod(const RewriteMethodPtr& method);
246 
248  RewriteMethodPtr getMultiTermRewriteMethod();
249 
251  void setLocale(std::locale locale);
252 
254  std::locale getLocale();
255 
260  void setDateResolution(DateTools::Resolution dateResolution);
261 
265  void setDateResolution(const String& fieldName, DateTools::Resolution dateResolution);
266 
269  DateTools::Resolution getDateResolution(const String& fieldName);
270 
277  void setRangeCollator(const CollatorPtr& rc);
278 
280  CollatorPtr getRangeCollator();
281 
283  static int main(Collection<String> args);
284 
287  int32_t Conjunction();
288  int32_t Modifiers();
289 
291  virtual QueryPtr TopLevelQuery(const String& field);
292 
293  virtual QueryPtr ParseQuery(const String& field);
294  virtual QueryPtr ParseClause(const String& field);
295  virtual QueryPtr ParseTerm(const String& field);
296 
298  virtual void ReInit(const QueryParserCharStreamPtr& stream);
299 
301  virtual void ReInit(const QueryParserTokenManagerPtr& tokenMgr);
302 
304  virtual QueryParserTokenPtr getNextToken();
305 
307  virtual QueryParserTokenPtr getToken(int32_t index);
308 
310  virtual void generateParseException();
311 
313  virtual void enable_tracing();
314 
316  virtual void disable_tracing();
317 
318 protected:
320  void ConstructParser(const QueryParserCharStreamPtr& stream, const QueryParserTokenManagerPtr& tokenMgr);
321 
322  virtual void addClause(Collection<BooleanClausePtr> clauses, int32_t conj, int32_t mods, const QueryPtr& q);
323 
326  virtual QueryPtr getFieldQuery(const String& field, const String& queryText);
327 
330  virtual QueryPtr getFieldQuery(const String& field, const String& queryText, int32_t slop);
331 
333  virtual QueryPtr getRangeQuery(const String& field, const String& part1, const String& part2, bool inclusive);
334 
337  BooleanQueryPtr newBooleanQuery(bool disableCoord);
338 
343  BooleanClausePtr newBooleanClause(const QueryPtr& q, BooleanClause::Occur occur);
344 
348  QueryPtr newTermQuery(const TermPtr& term);
349 
352  PhraseQueryPtr newPhraseQuery();
353 
356  MultiPhraseQueryPtr newMultiPhraseQuery();
357 
361  QueryPtr newPrefixQuery(const TermPtr& prefix);
362 
368  QueryPtr newFuzzyQuery(const TermPtr& term, double minimumSimilarity, int32_t prefixLength);
369 
376  QueryPtr newRangeQuery(const String& field, const String& part1, const String& part2, bool inclusive);
377 
380  QueryPtr newMatchAllDocsQuery();
381 
385  QueryPtr newWildcardQuery(const TermPtr& term);
386 
394  virtual QueryPtr getBooleanQuery(Collection<BooleanClausePtr> clauses);
395 
404  virtual QueryPtr getBooleanQuery(Collection<BooleanClausePtr> clauses, bool disableCoord);
405 
421  virtual QueryPtr getWildcardQuery(const String& field, const String& termStr);
422 
437  virtual QueryPtr getPrefixQuery(const String& field, const String& termStr);
438 
445  virtual QueryPtr getFuzzyQuery(const String& field, const String& termStr, double minSimilarity);
446 
449  String discardEscapeChar(const String& input);
450 
452  static int32_t hexToInt(wchar_t c);
453 
456  static String escape(const String& s);
457 
458  bool jj_2_1(int32_t xla);
459  bool jj_3R_2();
460  bool jj_3_1();
461  bool jj_3R_3();
462 
463  QueryParserTokenPtr jj_consume_token(int32_t kind);
464  bool jj_scan_token(int32_t kind);
465  int32_t jj_ntk();
466  void jj_add_error_token(int32_t kind, int32_t pos);
467  void jj_rescan_token();
468  void jj_save(int32_t index, int32_t xla);
469 };
470 
471 }
472 
473 #endif

clucene.sourceforge.net