1 | /*------------------------------------------------------------------------------ |
2 | * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team |
3 | * |
4 | * Distributable under the terms of either the Apache License (Version 2.0) or |
5 | * the GNU Lesser General Public License, as specified in the COPYING file. |
6 | ------------------------------------------------------------------------------*/ |
7 | #ifndef _lucene_search_RangeQuery_ |
8 | #define _lucene_search_RangeQuery_ |
9 | |
10 | //#include "SearchHeader.h" |
11 | //#include "Scorer.h" |
12 | //#include "TermQuery.h" |
13 | #include "Query.h" |
14 | |
15 | CL_CLASS_DEF(index,Term) |
16 | //#include "CLucene/index/Terms.h" |
17 | |
18 | CL_CLASS_DEF(util,StringBuffer) |
19 | |
20 | |
21 | CL_NS_DEF(search) |
22 | |
23 | /** |
24 | * A Query that matches documents within an exclusive range. A RangeQuery |
25 | * is built by QueryParser for input like <code>[010 TO 120]</code> but only if the QueryParser has |
26 | * the useOldRangeQuery property set to true. The QueryParser default behaviour is to use |
27 | * the newer ConstantScoreRangeQuery class. This is generally preferable because: |
28 | * <ul> |
29 | * <li>It is faster than RangeQuery</li> |
30 | * <li>Unlike RangeQuery, it does not cause a BooleanQuery.TooManyClauses exception if the range of values is large</li> |
31 | * <li>Unlike RangeQuery it does not influence scoring based on the scarcity of individual terms that may match</li> |
32 | * </ul> |
33 | * |
34 | * |
35 | * @see ConstantScoreRangeQuery |
36 | * |
37 | * |
38 | * @version $Id: RangeQuery.java 520891 2007-03-21 13:58:47Z yonik $ |
39 | */ |
40 | class CLUCENE_EXPORT RangeQuery: public Query |
41 | { |
42 | private: |
43 | CL_NS(index)::Term* lowerTerm; |
44 | CL_NS(index)::Term* upperTerm; |
45 | bool inclusive; |
46 | protected: |
47 | RangeQuery(const RangeQuery& clone); |
48 | |
49 | public: |
50 | /** Constructs a query selecting all terms greater than |
51 | * <code>lowerTerm</code> but less than <code>upperTerm</code>. |
52 | * There must be at least one term and either term may be null, |
53 | * in which case there is no bound on that side, but if there are |
54 | * two terms, both terms <b>must</b> be for the same field. |
55 | */ |
56 | RangeQuery(CL_NS(index)::Term* LowerTerm, CL_NS(index)::Term* UpperTerm, const bool Inclusive); |
57 | ~RangeQuery(); |
58 | |
59 | const char* getObjectName() const; |
60 | static const char* getClassName(); |
61 | |
62 | /** |
63 | * FIXME: Describe <code>rewrite</code> method here. |
64 | * |
65 | * @param reader an <code>IndexReader</code> value |
66 | * @return a <code>Query</code> value |
67 | * @exception IOException if an error occurs |
68 | */ |
69 | Query* rewrite(CL_NS(index)::IndexReader* reader); |
70 | |
71 | Query* combine(CL_NS(util)::ArrayBase<Query*>* queries); |
72 | |
73 | /** Prints a user-readable version of this query. */ |
74 | TCHAR* toString(const TCHAR* field) const; |
75 | |
76 | Query* clone() const; |
77 | |
78 | bool equals(Query * other) const; |
79 | |
80 | /** Returns the lower term of this range query */ |
81 | CL_NS(index)::Term* getLowerTerm(bool pointer=true) const; |
82 | /** Returns the upper term of this range query */ |
83 | CL_NS(index)::Term* getUpperTerm(bool pointer=true) const; |
84 | bool isInclusive() const; |
85 | /** Returns <code>true</code> if the range query is inclusive */ |
86 | const TCHAR* getField() const; |
87 | |
88 | size_t hashCode() const; |
89 | }; |
90 | |
91 | CL_NS_END |
92 | #endif |
93 | |