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_BooleanClause_
8 #define _lucene_search_BooleanClause_
9
CL_CLASS_DEF(util,StringBuffer)10 CL_CLASS_DEF(util,StringBuffer)
11 CL_CLASS_DEF(search,Query)
12
13 CL_NS_DEF(search)
14
15 // A clause in a BooleanQuery.
16 class CLUCENE_EXPORT BooleanClause:LUCENE_BASE {
17 public:
18 /** Specifies how clauses are to occur in matching documents. */
19 enum Occur {
20 /** Use this operator for clauses that <i>must</i> appear in the matching documents. */
21 MUST=1,
22
23 /** Use this operator for clauses that <i>should</i> appear in the
24 * matching documents. For a BooleanQuery with no <code>MUST</code>
25 * clauses one or more <code>SHOULD</code> clauses must match a document
26 * for the BooleanQuery to match.
27 * @see BooleanQuery#setMinimumNumberShouldMatch
28 */
29 SHOULD=2,
30
31 /** Use this operator for clauses that <i>must not</i> appear in the matching documents.
32 * Note that it is not possible to search for queries that only consist
33 * of a <code>MUST_NOT</code> clause. */
34 MUST_NOT=4
35 };
36 private:
37 /** The query whose matching documents are combined by the boolean query.
38 * @deprecated use {@link #setQuery(Query)} instead */
39 Query* query;
40
41 Occur occur;
42
43 /* Middle layer for the Occur enum; will be removed soon enough. */
44 void setFields(Occur occur);
45 public:
46 bool deleteQuery;
47
48
49 int32_t getClauseCount();
50
51
52 /** Constructs a BooleanClause with query <code>q</code>, required
53 * <code>r</code> and prohibited <code>p</code>.
54 * @deprecated use BooleanClause(Query, Occur) instead
55 * <ul>
56 * <li>For BooleanClause(query, true, false) use BooleanClause(query, BooleanClause.Occur.MUST)
57 * <li>For BooleanClause(query, false, false) use BooleanClause(query, BooleanClause.Occur.SHOULD)
58 * <li>For BooleanClause(query, false, true) use BooleanClause(query, BooleanClause.Occur.MUST_NOT)
59 * </ul>
60 */
61 BooleanClause(Query* q, const bool DeleteQuery,const bool req, const bool p);
62
63 BooleanClause(const BooleanClause& clone);
64
65 /** Constructs a BooleanClause.
66 */
67 BooleanClause(Query* q, const bool DeleteQuery, Occur o);
68
69
70 BooleanClause* clone() const;
71
72 ~BooleanClause();
73
74
75 /** Returns true if <code>o</code> is equal to this. */
76 bool equals(const BooleanClause* other) const;
77
78 /** Returns a hash code value for this object.*/
79 size_t hashCode() const;
80
81 Occur getOccur() const;
82 void setOccur(Occur o);
83
84 Query* getQuery() const;
85 void setQuery(Query* q);
86
87 bool isProhibited() const;
88 bool isRequired() const;
89
90 TCHAR* toString() const;
91
92 public: // TODO: Make private and remove for CLucene 2.3.2
93 /** If true, documents documents which <i>do not</i>
94 match this sub-query will <i>not</i> match the boolean query.
95 @deprecated use {@link #setOccur(BooleanClause.Occur)} instead */
96 bool required;
97
98 /** If true, documents documents which <i>do</i>
99 match this sub-query will <i>not</i> match the boolean query.
100 @deprecated use {@link #setOccur(BooleanClause.Occur)} instead */
101 bool prohibited;
102 };
103
104
105 CL_NS_END
106 #endif
107
108