1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
*
* Distributable under the terms of either the Apache License (Version 2.0) or
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#ifndef _lucene_search_BooleanQuery_
#define _lucene_search_BooleanQuery_
#if defined(_LUCENE_PRAGMA_ONCE)
# pragma once
#endif
#include "ConjunctionScorer.h"
#include "CLucene/index/IndexReader.h"
#include "CLucene/util/StringBuffer.h"
#include "SearchHeader.h"
#include "BooleanClause.h"
#include "BooleanScorer.h"
#include "Scorer.h"
CL_NS_DEF(search)
// A Query that matches documents matching boolean combinations of other
// queries, typically {@link TermQuery}s or {@link PhraseQuery}s.
class BooleanQuery:public Query {
public:
typedef CL_NS(util)::CLVector<BooleanClause*,CL_NS(util)::Deletor::Object<BooleanClause> > ClausesType;
private:
BooleanQuery::ClausesType clauses;
static size_t maxClauseCount;
class BooleanWeight: public Weight {
private:
Searcher* searcher;
CL_NS(util)::CLVector<Weight*,CL_NS(util)::Deletor::Object<Weight> > weights;
ClausesType* clauses;
BooleanQuery* parentQuery;
public:
BooleanWeight(Searcher* searcher,
CL_NS(util)::CLVector<BooleanClause*,CL_NS(util)::Deletor::Object<BooleanClause> >* clauses,
BooleanQuery* parentQuery);
~BooleanWeight();
Query* getQuery();
qreal getValue();
qreal sumOfSquaredWeights();
void normalize(qreal norm);
Scorer* scorer(CL_NS(index)::IndexReader* reader);
void explain(CL_NS(index)::IndexReader* reader, int32_t doc, Explanation* ret);
};//booleanweight
protected:
Weight* _createWeight(Searcher* searcher) {
return _CLNEW BooleanWeight(searcher,&clauses,this);
}
BooleanQuery(const BooleanQuery& clone);
public:
/** Constructs an empty boolean query. */
BooleanQuery();
~BooleanQuery();
const TCHAR* getQueryName() const;
static const TCHAR* getClassName();
/** Return the maximum number of clauses permitted, 1024 by default.
* Attempts to add more than the permitted number of clauses cause {@link
* TooManyClauses} to be thrown.*/
static size_t getMaxClauseCount();
/** Set the maximum number of clauses permitted. */
static void setMaxClauseCount(size_t maxClauseCount);
/** Adds a clause to a boolean query. Clauses may be:
* <ul>
* <li><code>required</code> which means that documents which <i>do not</i>
* match this sub-query will <i>not</i> match the boolean query;
* <li><code>prohibited</code> which means that documents which <i>do</i>
* match this sub-query will <i>not</i> match the boolean query; or
* <li>neither, in which case matched documents are neither prohibited from
* nor required to match the sub-query. However, a document must match at
* least 1 sub-query to match the boolean query.
* </ul>
* It is an error to specify a clause as both <code>required</code> and
* <code>prohibited</code>.
*
* @see #getMaxClauseCount()
*/
void add(Query* query, const bool required, const bool prohibited){
add(query,false,required,prohibited);
}
void add(Query* query, const bool deleteQuery, const bool required, const bool prohibited);
/** Copies the clauses of this query into the array.
* The array must be at least as long as getClauseCount()
* If you want to use the clauses, make sure you null terminate it.
*/
void getClauses(BooleanClause** clauses) const;
///@deprecated
_CL_DEPRECATED( getClauses(clauses) ) BooleanClause** getClauses() const;
/**
* Give client code access to clauses.size() so we know how
* large the array returned by getClauses is.
*/
size_t getClauseCount() const;
/** Adds a clause to a boolean query.
* @see #getMaxClauseCount()
*/
void add(BooleanClause* clause);
Query* rewrite(CL_NS(index)::IndexReader* reader);
Query* clone() const;
bool equals(Query* o) const;
/** Prints a user-readable version of this query. */
TCHAR* toString(const TCHAR* field) const;
/** Returns a hash code value for this object.*/
size_t hashCode() const;
};
CL_NS_END
#endif
|