author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team. |
|
4 |
** All rights reserved. |
|
5 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
6 |
** Portion Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 7 |
** All rights reserved. |
8 |
** |
|
9 |
** This file may be used under the terms of the GNU Lesser General Public |
|
10 |
** License version 2.1 as published by the Free Software Foundation and |
|
11 |
** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
12 |
** Please review the following information to ensure the GNU Lesser General |
|
13 |
** Public License version 2.1 requirements will be met: |
|
14 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
15 |
** |
|
16 |
****************************************************************************/ |
|
17 |
||
18 |
#include "qquery_p.h" |
|
19 |
#include "qclucene_global_p.h" |
|
20 |
||
21 |
#include <CLucene.h> |
|
22 |
#include <CLucene/search/PhraseQuery.h> |
|
23 |
#include <CLucene/search/SearchHeader.h> |
|
24 |
||
25 |
QT_BEGIN_NAMESPACE |
|
26 |
||
27 |
QCLuceneQueryPrivate::QCLuceneQueryPrivate() |
|
28 |
: QSharedData() |
|
29 |
{ |
|
30 |
query = 0; |
|
31 |
deleteCLuceneQuery = true; |
|
32 |
} |
|
33 |
||
34 |
QCLuceneQueryPrivate::QCLuceneQueryPrivate(const QCLuceneQueryPrivate &other) |
|
35 |
: QSharedData() |
|
36 |
{ |
|
37 |
query = _CL_POINTER(other.query); |
|
38 |
deleteCLuceneQuery = other.deleteCLuceneQuery; |
|
39 |
} |
|
40 |
||
41 |
QCLuceneQueryPrivate::~QCLuceneQueryPrivate() |
|
42 |
{ |
|
43 |
if (deleteCLuceneQuery) |
|
44 |
_CLDECDELETE(query); |
|
45 |
} |
|
46 |
||
47 |
||
48 |
QCLuceneQuery::QCLuceneQuery() |
|
49 |
: d(new QCLuceneQueryPrivate()) |
|
50 |
{ |
|
51 |
// nothing todo, private |
|
52 |
} |
|
53 |
||
54 |
QCLuceneQuery::~QCLuceneQuery() |
|
55 |
{ |
|
56 |
// nothing todo |
|
57 |
} |
|
58 |
||
59 |
void QCLuceneQuery::setBoost(qreal boost) |
|
60 |
{ |
|
61 |
d->query->setBoost(qreal(boost)); |
|
62 |
} |
|
63 |
||
64 |
qreal QCLuceneQuery::getBoost() const |
|
65 |
{ |
|
66 |
return qreal(d->query->getBoost()); |
|
67 |
} |
|
68 |
||
69 |
QString QCLuceneQuery::getQueryName() const |
|
70 |
{ |
|
71 |
return TCharToQString(d->query->getQueryName()); |
|
72 |
} |
|
73 |
||
74 |
bool QCLuceneQuery::instanceOf(const QString &other) const |
|
75 |
{ |
|
76 |
if (other == getQueryName()) |
|
77 |
return true; |
|
78 |
||
79 |
return false; |
|
80 |
} |
|
81 |
||
82 |
QString QCLuceneQuery::toString(const QString &field) const |
|
83 |
{ |
|
84 |
TCHAR *fieldName = QStringToTChar(field); |
|
85 |
QString retValue = TCharToQString(d->query->toString(fieldName)); |
|
86 |
delete [] fieldName; |
|
87 |
||
88 |
return retValue; |
|
89 |
} |
|
90 |
||
91 |
quint32 QCLuceneQuery::hashCode() const |
|
92 |
{ |
|
93 |
return quint32(d->query->hashCode()); |
|
94 |
} |
|
95 |
||
96 |
QString QCLuceneQuery::toString() const |
|
97 |
{ |
|
98 |
return TCharToQString(d->query->toString()); |
|
99 |
} |
|
100 |
||
101 |
bool QCLuceneQuery::equals(const QCLuceneQuery &other) const |
|
102 |
{ |
|
103 |
return d->query->equals(other.d->query); |
|
104 |
} |
|
105 |
||
106 |
||
107 |
QCLucenePrefixQuery::QCLucenePrefixQuery(const QCLuceneTerm &prefix) |
|
108 |
: QCLuceneQuery() |
|
109 |
, prefix(prefix) |
|
110 |
{ |
|
111 |
d->query = new lucene::search::PrefixQuery(prefix.d->term); |
|
112 |
} |
|
113 |
||
114 |
QCLucenePrefixQuery::~QCLucenePrefixQuery() |
|
115 |
{ |
|
116 |
// nothing todo |
|
117 |
} |
|
118 |
||
119 |
QString QCLucenePrefixQuery::getClassName() |
|
120 |
{ |
|
121 |
return TCharToQString(lucene::search::PrefixQuery::getClassName()); |
|
122 |
} |
|
123 |
||
124 |
QCLuceneTerm QCLucenePrefixQuery::getPrefix() const |
|
125 |
{ |
|
126 |
return prefix; |
|
127 |
} |
|
128 |
||
129 |
||
130 |
QCLuceneRangeQuery::QCLuceneRangeQuery(const QCLuceneTerm &lowerTerm, |
|
131 |
const QCLuceneTerm &upperTerm, |
|
132 |
bool inclusive) |
|
133 |
: QCLuceneQuery() |
|
134 |
, lowerTerm(lowerTerm) |
|
135 |
, upperTerm(upperTerm) |
|
136 |
{ |
|
137 |
d->query = new lucene::search::RangeQuery(lowerTerm.d->term, |
|
138 |
upperTerm.d->term, inclusive); |
|
139 |
} |
|
140 |
||
141 |
QCLuceneRangeQuery::~QCLuceneRangeQuery() |
|
142 |
{ |
|
143 |
// nothing todo |
|
144 |
} |
|
145 |
||
146 |
QString QCLuceneRangeQuery::getClassName() |
|
147 |
{ |
|
148 |
return TCharToQString(lucene::search::RangeQuery::getClassName()); |
|
149 |
} |
|
150 |
||
151 |
QCLuceneTerm QCLuceneRangeQuery::getLowerTerm() const |
|
152 |
{ |
|
153 |
return lowerTerm; |
|
154 |
} |
|
155 |
||
156 |
QCLuceneTerm QCLuceneRangeQuery::getUpperTerm() const |
|
157 |
{ |
|
158 |
return upperTerm; |
|
159 |
} |
|
160 |
||
161 |
bool QCLuceneRangeQuery::isInclusive() const |
|
162 |
{ |
|
163 |
lucene::search::RangeQuery *query = |
|
164 |
static_cast<lucene::search::RangeQuery*> (d->query); |
|
165 |
||
166 |
if (query == 0) |
|
167 |
return false; |
|
168 |
||
169 |
return query->isInclusive(); |
|
170 |
} |
|
171 |
||
172 |
QString QCLuceneRangeQuery::getField() const |
|
173 |
{ |
|
174 |
lucene::search::RangeQuery *query = |
|
175 |
static_cast<lucene::search::RangeQuery*> (d->query); |
|
176 |
||
177 |
if (query == 0) |
|
178 |
return QString(); |
|
179 |
||
180 |
return TCharToQString(query->getField()); |
|
181 |
} |
|
182 |
||
183 |
||
184 |
QCLuceneTermQuery::QCLuceneTermQuery(const QCLuceneTerm &term) |
|
185 |
: QCLuceneQuery() |
|
186 |
, term(term) |
|
187 |
{ |
|
188 |
d->query = new lucene::search::TermQuery(term.d->term); |
|
189 |
} |
|
190 |
||
191 |
QCLuceneTermQuery::~QCLuceneTermQuery() |
|
192 |
{ |
|
193 |
// nothing todo |
|
194 |
} |
|
195 |
||
196 |
QString QCLuceneTermQuery::getClassName() |
|
197 |
{ |
|
198 |
return TCharToQString(lucene::search::TermQuery::getClassName()); |
|
199 |
} |
|
200 |
||
201 |
QCLuceneTerm QCLuceneTermQuery::getTerm() const |
|
202 |
{ |
|
203 |
return term; |
|
204 |
} |
|
205 |
||
206 |
||
207 |
QCLuceneBooleanQuery::QCLuceneBooleanQuery() |
|
208 |
: QCLuceneQuery() |
|
209 |
{ |
|
210 |
d->query = new lucene::search::BooleanQuery(); |
|
211 |
} |
|
212 |
||
213 |
QCLuceneBooleanQuery::~QCLuceneBooleanQuery() |
|
214 |
{ |
|
215 |
qDeleteAll(queries); |
|
216 |
} |
|
217 |
||
218 |
QString QCLuceneBooleanQuery::getClassName() |
|
219 |
{ |
|
220 |
return TCharToQString(lucene::search::BooleanQuery::getClassName()); |
|
221 |
} |
|
222 |
||
223 |
quint32 QCLuceneBooleanQuery::getClauseCount() const |
|
224 |
{ |
|
225 |
lucene::search::BooleanQuery *query = |
|
226 |
static_cast<lucene::search::BooleanQuery*> (d->query); |
|
227 |
||
228 |
if (query == 0) |
|
229 |
return 1024; |
|
230 |
||
231 |
return quint32(query->getClauseCount()); |
|
232 |
} |
|
233 |
||
234 |
quint32 QCLuceneBooleanQuery::getMaxClauseCount() const |
|
235 |
{ |
|
236 |
lucene::search::BooleanQuery *query = |
|
237 |
static_cast<lucene::search::BooleanQuery*> (d->query); |
|
238 |
||
239 |
if (query == 0) |
|
240 |
return 1024; |
|
241 |
||
242 |
return quint32(query->getMaxClauseCount()); |
|
243 |
} |
|
244 |
||
245 |
void QCLuceneBooleanQuery::setMaxClauseCount(quint32 maxClauseCount) |
|
246 |
{ |
|
247 |
lucene::search::BooleanQuery *query = |
|
248 |
static_cast<lucene::search::BooleanQuery*> (d->query); |
|
249 |
||
250 |
if (query == 0) |
|
251 |
return; |
|
252 |
||
253 |
query->setMaxClauseCount(size_t(maxClauseCount)); |
|
254 |
} |
|
255 |
||
256 |
void QCLuceneBooleanQuery::add(QCLuceneQuery *query, bool required, bool prohibited) |
|
257 |
{ |
|
258 |
add(query, false, required, prohibited); |
|
259 |
} |
|
260 |
||
261 |
void QCLuceneBooleanQuery::add(QCLuceneQuery *query, bool delQuery, |
|
262 |
bool required, bool prohibited) |
|
263 |
{ |
|
264 |
lucene::search::BooleanQuery *booleanQuery = |
|
265 |
static_cast<lucene::search::BooleanQuery*> (d->query); |
|
266 |
||
267 |
if (booleanQuery == 0) |
|
268 |
return; |
|
269 |
||
270 |
booleanQuery->add(query->d->query, delQuery, required, prohibited); |
|
271 |
||
272 |
if (delQuery) { |
|
273 |
queries.append(query); |
|
274 |
query->d->deleteCLuceneQuery = false; |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
||
279 |
QCLucenePhraseQuery::QCLucenePhraseQuery() |
|
280 |
: QCLuceneQuery() |
|
281 |
{ |
|
282 |
d->query = new lucene::search::PhraseQuery(); |
|
283 |
} |
|
284 |
||
285 |
QCLucenePhraseQuery::~QCLucenePhraseQuery() |
|
286 |
{ |
|
287 |
termList.clear(); |
|
288 |
} |
|
289 |
||
290 |
QString QCLucenePhraseQuery::getClassName() |
|
291 |
{ |
|
292 |
return TCharToQString(lucene::search::RangeQuery::getClassName()); |
|
293 |
} |
|
294 |
||
295 |
qint32 QCLucenePhraseQuery::getSlop() const |
|
296 |
{ |
|
297 |
lucene::search::PhraseQuery *phraseQuery = |
|
298 |
static_cast<lucene::search::PhraseQuery*> (d->query); |
|
299 |
||
300 |
if (phraseQuery == 0) |
|
301 |
return 0; |
|
302 |
||
303 |
return qint32(phraseQuery->getSlop()); |
|
304 |
} |
|
305 |
||
306 |
void QCLucenePhraseQuery::setSlop(const qint32 slop) |
|
307 |
{ |
|
308 |
lucene::search::PhraseQuery *phraseQuery = |
|
309 |
static_cast<lucene::search::PhraseQuery*> (d->query); |
|
310 |
||
311 |
if (phraseQuery == 0) |
|
312 |
return; |
|
313 |
||
314 |
phraseQuery->setSlop(int32_t(slop)); |
|
315 |
} |
|
316 |
||
317 |
void QCLucenePhraseQuery::addTerm(const QCLuceneTerm &term) |
|
318 |
{ |
|
319 |
lucene::search::PhraseQuery *phraseQuery = |
|
320 |
static_cast<lucene::search::PhraseQuery*> (d->query); |
|
321 |
||
322 |
if (phraseQuery == 0) |
|
323 |
return; |
|
324 |
||
325 |
termList.append(term); |
|
326 |
phraseQuery->add(term.d->term); |
|
327 |
} |
|
328 |
||
329 |
void QCLucenePhraseQuery::addTerm(const QCLuceneTerm &term, qint32 position) |
|
330 |
{ |
|
331 |
lucene::search::PhraseQuery *phraseQuery = |
|
332 |
static_cast<lucene::search::PhraseQuery*> (d->query); |
|
333 |
||
334 |
if (phraseQuery == 0) |
|
335 |
return; |
|
336 |
||
337 |
termList.insert(position, term); |
|
338 |
phraseQuery->add(term.d->term, int32_t(position)); |
|
339 |
||
340 |
} |
|
341 |
||
342 |
QString QCLucenePhraseQuery::getFieldName() const |
|
343 |
{ |
|
344 |
lucene::search::PhraseQuery *phraseQuery = |
|
345 |
static_cast<lucene::search::PhraseQuery*> (d->query); |
|
346 |
||
347 |
if (phraseQuery == 0) |
|
348 |
return QString(); |
|
349 |
||
350 |
return TCharToQString(phraseQuery->getFieldName()); |
|
351 |
} |
|
352 |
||
353 |
QList<QCLuceneTerm> QCLucenePhraseQuery::getTerms() const |
|
354 |
{ |
|
355 |
return termList; |
|
356 |
} |
|
357 |
||
358 |
QT_END_NAMESPACE |