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