|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team. |
|
4 ** All rights reserved. |
|
5 ** |
|
6 ** Portion Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 "qindexreader_p.h" |
|
19 #include "qclucene_global_p.h" |
|
20 |
|
21 #include <CLucene.h> |
|
22 #include <CLucene/index/IndexReader.h> |
|
23 |
|
24 QT_BEGIN_NAMESPACE |
|
25 |
|
26 QCLuceneIndexReaderPrivate::QCLuceneIndexReaderPrivate() |
|
27 : QSharedData() |
|
28 { |
|
29 reader = 0; |
|
30 deleteCLuceneIndexReader = true; |
|
31 } |
|
32 |
|
33 QCLuceneIndexReaderPrivate::QCLuceneIndexReaderPrivate(const QCLuceneIndexReaderPrivate &other) |
|
34 : QSharedData() |
|
35 { |
|
36 reader = _CL_POINTER(other.reader); |
|
37 deleteCLuceneIndexReader = other.deleteCLuceneIndexReader; |
|
38 } |
|
39 |
|
40 QCLuceneIndexReaderPrivate::~QCLuceneIndexReaderPrivate() |
|
41 { |
|
42 if (deleteCLuceneIndexReader) |
|
43 _CLDECDELETE(reader); |
|
44 } |
|
45 |
|
46 |
|
47 QCLuceneIndexReader::QCLuceneIndexReader() |
|
48 : d(new QCLuceneIndexReaderPrivate()) |
|
49 { |
|
50 // nothing todo, private |
|
51 } |
|
52 |
|
53 QCLuceneIndexReader::~QCLuceneIndexReader() |
|
54 { |
|
55 // nothing todo |
|
56 } |
|
57 |
|
58 bool QCLuceneIndexReader::isLuceneFile(const QString &filename) |
|
59 { |
|
60 using namespace lucene::index; |
|
61 |
|
62 return IndexReader::isLuceneFile(filename); |
|
63 } |
|
64 |
|
65 bool QCLuceneIndexReader::indexExists(const QString &directory) |
|
66 { |
|
67 using namespace lucene::index; |
|
68 return IndexReader::indexExists(directory); |
|
69 } |
|
70 |
|
71 QCLuceneIndexReader QCLuceneIndexReader::open(const QString &path) |
|
72 { |
|
73 using namespace lucene::index; |
|
74 |
|
75 QCLuceneIndexReader indexReader; |
|
76 indexReader.d->reader = IndexReader::open(path); |
|
77 |
|
78 return indexReader; |
|
79 } |
|
80 |
|
81 void QCLuceneIndexReader::unlock(const QString &path) |
|
82 { |
|
83 using namespace lucene::index; |
|
84 IndexReader::unlock(path); |
|
85 } |
|
86 |
|
87 bool QCLuceneIndexReader::isLocked(const QString &directory) |
|
88 { |
|
89 using namespace lucene::index; |
|
90 return IndexReader::isLocked(directory); |
|
91 } |
|
92 |
|
93 quint64 QCLuceneIndexReader::lastModified(const QString &directory) |
|
94 { |
|
95 using namespace lucene::index; |
|
96 return quint64(IndexReader::lastModified(directory)); |
|
97 } |
|
98 |
|
99 qint64 QCLuceneIndexReader::getCurrentVersion(const QString &directory) |
|
100 { |
|
101 using namespace lucene::index; |
|
102 return qint64(IndexReader::getCurrentVersion(directory)); |
|
103 } |
|
104 |
|
105 void QCLuceneIndexReader::close() |
|
106 { |
|
107 d->reader->close(); |
|
108 } |
|
109 |
|
110 bool QCLuceneIndexReader::isCurrent() |
|
111 { |
|
112 return d->reader->isCurrent(); |
|
113 } |
|
114 |
|
115 void QCLuceneIndexReader::undeleteAll() |
|
116 { |
|
117 d->reader->undeleteAll(); |
|
118 } |
|
119 |
|
120 qint64 QCLuceneIndexReader::getVersion() |
|
121 { |
|
122 return qint64(d->reader->getVersion()); |
|
123 } |
|
124 |
|
125 void QCLuceneIndexReader::deleteDocument(qint32 docNum) |
|
126 { |
|
127 d->reader->deleteDocument(int32_t(docNum)); |
|
128 } |
|
129 |
|
130 bool QCLuceneIndexReader::hasNorms(const QString &field) |
|
131 { |
|
132 TCHAR *fieldName = QStringToTChar(field); |
|
133 bool retValue = d->reader->hasNorms(fieldName); |
|
134 delete [] fieldName; |
|
135 |
|
136 return retValue; |
|
137 } |
|
138 |
|
139 qint32 QCLuceneIndexReader::deleteDocuments(const QCLuceneTerm &term) |
|
140 { |
|
141 return d->reader->deleteDocuments(term.d->term); |
|
142 } |
|
143 |
|
144 bool QCLuceneIndexReader::document(qint32 index, QCLuceneDocument &document) |
|
145 { |
|
146 if (!document.d->document) |
|
147 document.d->document = new lucene::document::Document(); |
|
148 |
|
149 if (d->reader->document(int32_t(index), document.d->document)) |
|
150 return true; |
|
151 |
|
152 return false; |
|
153 } |
|
154 |
|
155 void QCLuceneIndexReader::setNorm(qint32 doc, const QString &field, qreal value) |
|
156 { |
|
157 TCHAR *fieldName = QStringToTChar(field); |
|
158 d->reader->setNorm(int32_t(doc), fieldName, qreal(value)); |
|
159 delete [] fieldName; |
|
160 } |
|
161 |
|
162 void QCLuceneIndexReader::setNorm(qint32 doc, const QString &field, quint8 value) |
|
163 { |
|
164 TCHAR *fieldName = QStringToTChar(field); |
|
165 d->reader->setNorm(int32_t(doc), fieldName, uint8_t(value)); |
|
166 delete [] fieldName; |
|
167 } |
|
168 |
|
169 QT_END_NAMESPACE |