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 "qsearchable_p.h" |
|
19 |
||
20 |
#include <CLucene.h> |
|
21 |
#include <CLucene/search/SearchHeader.h> |
|
22 |
||
23 |
QT_BEGIN_NAMESPACE |
|
24 |
||
25 |
QCLuceneSearchablePrivate::QCLuceneSearchablePrivate() |
|
26 |
: QSharedData() |
|
27 |
{ |
|
28 |
searchable = 0; |
|
29 |
deleteCLuceneSearchable = true; |
|
30 |
} |
|
31 |
||
32 |
QCLuceneSearchablePrivate::QCLuceneSearchablePrivate(const QCLuceneSearchablePrivate &other) |
|
33 |
: QSharedData() |
|
34 |
{ |
|
35 |
searchable = _CL_POINTER(other.searchable); |
|
36 |
deleteCLuceneSearchable = other.deleteCLuceneSearchable; |
|
37 |
} |
|
38 |
||
39 |
QCLuceneSearchablePrivate::~QCLuceneSearchablePrivate() |
|
40 |
{ |
|
41 |
if (deleteCLuceneSearchable) |
|
42 |
_CLDECDELETE(searchable); |
|
43 |
} |
|
44 |
||
45 |
||
46 |
QCLuceneSearchable::QCLuceneSearchable() |
|
47 |
: d(new QCLuceneSearchablePrivate()) |
|
48 |
{ |
|
49 |
// nothing todo |
|
50 |
} |
|
51 |
||
52 |
QCLuceneSearchable::~QCLuceneSearchable() |
|
53 |
{ |
|
54 |
// nothing todo |
|
55 |
} |
|
56 |
||
57 |
||
58 |
QCLuceneSearcher::QCLuceneSearcher() |
|
59 |
: QCLuceneSearchable() |
|
60 |
{ |
|
61 |
// nothing todo |
|
62 |
} |
|
63 |
||
64 |
QCLuceneSearcher::~QCLuceneSearcher() |
|
65 |
{ |
|
66 |
// nothing todo; |
|
67 |
} |
|
68 |
||
69 |
QCLuceneHits QCLuceneSearcher::search(const QCLuceneQuery &query) |
|
70 |
{ |
|
71 |
return search(query, QCLuceneFilter()); |
|
72 |
} |
|
73 |
||
74 |
QCLuceneHits QCLuceneSearcher::search(const QCLuceneQuery &query, |
|
75 |
const QCLuceneFilter &filter) |
|
76 |
{ |
|
77 |
return QCLuceneHits(*this, query, filter); |
|
78 |
} |
|
79 |
||
80 |
QCLuceneHits QCLuceneSearcher::search(const QCLuceneQuery &query, |
|
81 |
const QCLuceneSort &sort) |
|
82 |
{ |
|
83 |
return QCLuceneHits(*this, query, QCLuceneFilter(), sort); |
|
84 |
} |
|
85 |
||
86 |
QCLuceneHits QCLuceneSearcher::search(const QCLuceneQuery &query, |
|
87 |
const QCLuceneFilter &filter, |
|
88 |
const QCLuceneSort &sort) |
|
89 |
{ |
|
90 |
return QCLuceneHits(*this, query, filter, sort); |
|
91 |
} |
|
92 |
||
93 |
||
94 |
QCLuceneIndexSearcher::QCLuceneIndexSearcher(const QString &path) |
|
95 |
: QCLuceneSearcher() |
|
96 |
{ |
|
97 |
lucene::search::IndexSearcher *searcher = |
|
98 |
new lucene::search::IndexSearcher(path); |
|
99 |
||
100 |
reader.d->reader = searcher->getReader(); |
|
101 |
reader.d->deleteCLuceneIndexReader = false; |
|
102 |
||
103 |
d->searchable = searcher; |
|
104 |
} |
|
105 |
||
106 |
QCLuceneIndexSearcher::QCLuceneIndexSearcher(const QCLuceneIndexReader &reader) |
|
107 |
: QCLuceneSearcher() |
|
108 |
, reader(reader) |
|
109 |
{ |
|
110 |
d->searchable = new lucene::search::IndexSearcher(reader.d->reader); |
|
111 |
} |
|
112 |
||
113 |
QCLuceneIndexSearcher::~QCLuceneIndexSearcher() |
|
114 |
{ |
|
115 |
// nothing todo |
|
116 |
} |
|
117 |
||
118 |
void QCLuceneIndexSearcher::close() |
|
119 |
{ |
|
120 |
d->searchable->close(); |
|
121 |
} |
|
122 |
||
123 |
qint32 QCLuceneIndexSearcher::maxDoc() const |
|
124 |
{ |
|
125 |
return qint32(d->searchable->maxDoc()); |
|
126 |
} |
|
127 |
||
128 |
QCLuceneIndexReader QCLuceneIndexSearcher::getReader() |
|
129 |
{ |
|
130 |
return reader; |
|
131 |
} |
|
132 |
||
133 |
bool QCLuceneIndexSearcher::doc(qint32 i, QCLuceneDocument &document) |
|
134 |
{ |
|
135 |
return d->searchable->doc(int32_t(i), document.d->document); |
|
136 |
} |
|
137 |
||
138 |
||
139 |
QCLuceneMultiSearcher::QCLuceneMultiSearcher(const QList<QCLuceneSearchable> searchables) |
|
140 |
: QCLuceneSearcher() |
|
141 |
{ |
|
142 |
lucene::search::Searchable** list= |
|
143 |
_CL_NEWARRAY(lucene::search::Searchable*, searchables.count()); |
|
144 |
||
145 |
d->searchable = new lucene::search::MultiSearcher(list); |
|
146 |
||
147 |
_CLDELETE_ARRAY(list); |
|
148 |
} |
|
149 |
||
150 |
QCLuceneMultiSearcher::~QCLuceneMultiSearcher() |
|
151 |
{ |
|
152 |
// nothing todo |
|
153 |
} |
|
154 |
||
155 |
void QCLuceneMultiSearcher::close() |
|
156 |
{ |
|
157 |
d->searchable->close(); |
|
158 |
} |
|
159 |
||
160 |
qint32 QCLuceneMultiSearcher::maxDoc() const |
|
161 |
{ |
|
162 |
return qint32(d->searchable->maxDoc()); |
|
163 |
} |
|
164 |
||
165 |
qint32 QCLuceneMultiSearcher::subDoc(qint32 index) const |
|
166 |
{ |
|
167 |
lucene::search::MultiSearcher *searcher = |
|
168 |
static_cast<lucene::search::MultiSearcher*> (d->searchable); |
|
169 |
||
170 |
if (searcher == 0) |
|
171 |
return 0; |
|
172 |
||
173 |
return qint32(searcher->subDoc(int32_t(index))); |
|
174 |
} |
|
175 |
||
176 |
qint32 QCLuceneMultiSearcher::subSearcher(qint32 index) const |
|
177 |
{ |
|
178 |
lucene::search::MultiSearcher *searcher = |
|
179 |
static_cast<lucene::search::MultiSearcher*> (d->searchable); |
|
180 |
||
181 |
if (searcher == 0) |
|
182 |
return 0; |
|
183 |
||
184 |
return qint32(searcher->subSearcher(int32_t(index))); |
|
185 |
} |
|
186 |
||
187 |
qint32 QCLuceneMultiSearcher::searcherIndex(qint32 index) const |
|
188 |
{ |
|
189 |
lucene::search::MultiSearcher *searcher = |
|
190 |
static_cast<lucene::search::MultiSearcher*> (d->searchable); |
|
191 |
||
192 |
if (searcher == 0) |
|
193 |
return 0; |
|
194 |
||
195 |
return qint32(searcher->searcherIndex(int32_t(index))); |
|
196 |
} |
|
197 |
||
198 |
bool QCLuceneMultiSearcher::doc(qint32 i, QCLuceneDocument &document) |
|
199 |
{ |
|
200 |
return d->searchable->doc(int32_t(i), document.d->document); |
|
201 |
} |
|
202 |
||
203 |
QT_END_NAMESPACE |