0
|
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 "qindexwriter_p.h"
|
|
19 |
#include "qindexreader_p.h"
|
|
20 |
|
|
21 |
#include <CLucene.h>
|
|
22 |
#include <CLucene/index/IndexWriter.h>
|
|
23 |
|
|
24 |
QT_BEGIN_NAMESPACE
|
|
25 |
|
|
26 |
QCLuceneIndexWriterPrivate::QCLuceneIndexWriterPrivate()
|
|
27 |
: QSharedData()
|
|
28 |
{
|
|
29 |
writer = 0;
|
|
30 |
deleteCLuceneIndexWriter = true;
|
|
31 |
}
|
|
32 |
|
|
33 |
QCLuceneIndexWriterPrivate::QCLuceneIndexWriterPrivate(const QCLuceneIndexWriterPrivate &other)
|
|
34 |
: QSharedData()
|
|
35 |
{
|
|
36 |
writer = _CL_POINTER(other.writer);
|
|
37 |
deleteCLuceneIndexWriter = other.deleteCLuceneIndexWriter;
|
|
38 |
}
|
|
39 |
|
|
40 |
QCLuceneIndexWriterPrivate::~QCLuceneIndexWriterPrivate()
|
|
41 |
{
|
|
42 |
if (deleteCLuceneIndexWriter)
|
|
43 |
_CLDECDELETE(writer);
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
QCLuceneIndexWriter::QCLuceneIndexWriter(const QString &path,
|
|
48 |
QCLuceneAnalyzer &analyzer,
|
|
49 |
bool create, bool closeDir)
|
|
50 |
: d(new QCLuceneIndexWriterPrivate())
|
|
51 |
, analyzer(analyzer)
|
|
52 |
{
|
|
53 |
d->writer = new lucene::index::IndexWriter(path,
|
|
54 |
analyzer.d->analyzer, create, closeDir);
|
|
55 |
}
|
|
56 |
|
|
57 |
QCLuceneIndexWriter::~QCLuceneIndexWriter()
|
|
58 |
{
|
|
59 |
// nothing todo
|
|
60 |
}
|
|
61 |
|
|
62 |
void QCLuceneIndexWriter::close()
|
|
63 |
{
|
|
64 |
d->writer->close();
|
|
65 |
}
|
|
66 |
|
|
67 |
void QCLuceneIndexWriter::optimize()
|
|
68 |
{
|
|
69 |
d->writer->optimize();
|
|
70 |
}
|
|
71 |
|
|
72 |
qint32 QCLuceneIndexWriter::docCount()
|
|
73 |
{
|
|
74 |
return qint32(d->writer->docCount());
|
|
75 |
}
|
|
76 |
|
|
77 |
QCLuceneAnalyzer QCLuceneIndexWriter::getAnalyzer()
|
|
78 |
{
|
|
79 |
return analyzer;
|
|
80 |
}
|
|
81 |
|
|
82 |
void QCLuceneIndexWriter::addIndexes(const QList<QCLuceneIndexReader*> &readers)
|
|
83 |
{
|
|
84 |
using namespace lucene::index;
|
|
85 |
IndexReader** readerArray = new IndexReader*[readers.count()];
|
|
86 |
|
|
87 |
for (int i = 0; i < readers.count(); ++i)
|
|
88 |
readerArray[i] = (readers.at(i))->d->reader;
|
|
89 |
|
|
90 |
d->writer->addIndexes(readerArray);
|
|
91 |
delete readerArray;
|
|
92 |
}
|
|
93 |
|
|
94 |
void QCLuceneIndexWriter::addDocument(QCLuceneDocument &doc,
|
|
95 |
QCLuceneAnalyzer &analyzer)
|
|
96 |
{
|
|
97 |
if (doc.d->document)
|
|
98 |
d->writer->addDocument(doc.d->document, analyzer.d->analyzer);
|
|
99 |
}
|
|
100 |
|
|
101 |
qint32 QCLuceneIndexWriter::getMaxFieldLength() const
|
|
102 |
{
|
|
103 |
return qint32(d->writer->getMaxFieldLength());
|
|
104 |
}
|
|
105 |
|
|
106 |
void QCLuceneIndexWriter::setMaxFieldLength(qint32 value)
|
|
107 |
{
|
|
108 |
d->writer->setMaxFieldLength(int32_t(value));
|
|
109 |
}
|
|
110 |
|
|
111 |
qint32 QCLuceneIndexWriter::getMaxBufferedDocs() const
|
|
112 |
{
|
|
113 |
return qint32(d->writer->getMaxBufferedDocs());
|
|
114 |
}
|
|
115 |
|
|
116 |
void QCLuceneIndexWriter::setMaxBufferedDocs(qint32 value)
|
|
117 |
{
|
|
118 |
d->writer->setMaxBufferedDocs(int32_t(value));
|
|
119 |
}
|
|
120 |
|
|
121 |
qint64 QCLuceneIndexWriter::getWriteLockTimeout() const
|
|
122 |
{
|
|
123 |
return qint64(d->writer->getWriteLockTimeout());
|
|
124 |
}
|
|
125 |
|
|
126 |
void QCLuceneIndexWriter::setWriteLockTimeout(qint64 writeLockTimeout)
|
|
127 |
{
|
|
128 |
d->writer->setWriteLockTimeout(int64_t(writeLockTimeout));
|
|
129 |
}
|
|
130 |
|
|
131 |
qint64 QCLuceneIndexWriter::getCommitLockTimeout() const
|
|
132 |
{
|
|
133 |
return qint64(d->writer->getCommitLockTimeout());
|
|
134 |
}
|
|
135 |
|
|
136 |
void QCLuceneIndexWriter::setCommitLockTimeout(qint64 commitLockTimeout)
|
|
137 |
{
|
|
138 |
d->writer->setCommitLockTimeout(int64_t(commitLockTimeout));
|
|
139 |
}
|
|
140 |
|
|
141 |
qint32 QCLuceneIndexWriter::getMergeFactor() const
|
|
142 |
{
|
|
143 |
return qint32(d->writer->getMergeFactor());
|
|
144 |
}
|
|
145 |
|
|
146 |
void QCLuceneIndexWriter::setMergeFactor(qint32 value)
|
|
147 |
{
|
|
148 |
d->writer->setMergeFactor(int32_t(value));
|
|
149 |
}
|
|
150 |
|
|
151 |
qint32 QCLuceneIndexWriter::getTermIndexInterval() const
|
|
152 |
{
|
|
153 |
return qint32(d->writer->getTermIndexInterval());
|
|
154 |
}
|
|
155 |
|
|
156 |
void QCLuceneIndexWriter::setTermIndexInterval(qint32 interval)
|
|
157 |
{
|
|
158 |
d->writer->setTermIndexInterval(int32_t(interval));
|
|
159 |
}
|
|
160 |
|
|
161 |
qint32 QCLuceneIndexWriter::getMinMergeDocs() const
|
|
162 |
{
|
|
163 |
return qint32(d->writer->getMinMergeDocs());
|
|
164 |
}
|
|
165 |
|
|
166 |
void QCLuceneIndexWriter::setMinMergeDocs(qint32 value)
|
|
167 |
{
|
|
168 |
d->writer->setMinMergeDocs(int32_t(value));
|
|
169 |
}
|
|
170 |
|
|
171 |
qint32 QCLuceneIndexWriter::getMaxMergeDocs() const
|
|
172 |
{
|
|
173 |
return qint32(d->writer->getMaxMergeDocs());
|
|
174 |
}
|
|
175 |
|
|
176 |
void QCLuceneIndexWriter::setMaxMergeDocs(qint32 value)
|
|
177 |
{
|
|
178 |
d->writer->setMaxMergeDocs(int32_t(value));
|
|
179 |
}
|
|
180 |
|
|
181 |
bool QCLuceneIndexWriter::getUseCompoundFile() const
|
|
182 |
{
|
|
183 |
return d->writer->getUseCompoundFile();
|
|
184 |
}
|
|
185 |
|
|
186 |
void QCLuceneIndexWriter::setUseCompoundFile(bool value)
|
|
187 |
{
|
|
188 |
d->writer->setUseCompoundFile(value);
|
|
189 |
}
|
|
190 |
|
|
191 |
QT_END_NAMESPACE
|