summaryrefslogtreecommitdiffstats
path: root/common/fulltextindex.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-27 12:18:06 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-07-27 13:15:22 +0200
commit0a6229931ac90fa8914dbdafef51adf5ca92a206 (patch)
tree9d4821ecc211842071f023a2465e9a5f4cdb3c7d /common/fulltextindex.cpp
parent5e421481b95bc46aae05260e0afc6aa32945e62f (diff)
downloadsink-0a6229931ac90fa8914dbdafef51adf5ca92a206.tar.gz
sink-0a6229931ac90fa8914dbdafef51adf5ca92a206.zip
All xapian stuff in a central place
Diffstat (limited to 'common/fulltextindex.cpp')
-rw-r--r--common/fulltextindex.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/common/fulltextindex.cpp b/common/fulltextindex.cpp
index 164a5b9..b1c6178 100644
--- a/common/fulltextindex.cpp
+++ b/common/fulltextindex.cpp
@@ -182,3 +182,37 @@ QVector<QByteArray> FulltextIndex::lookup(const QString &searchTerm)
182 return results; 182 return results;
183} 183}
184 184
185qint64 FulltextIndex::getDoccount() const
186{
187 if (!mDb) {
188 return -1;
189 }
190 try {
191 return mDb->get_doccount();
192 } catch (const Xapian::Error &) {
193 // Nothing to do, move along
194 }
195 return -1;
196}
197
198FulltextIndex::Result FulltextIndex::getIndexContent(const QByteArray &identifier) const
199{
200 if (!mDb) {
201 {};
202 }
203 try {
204 auto id = "Q" + identifier.toStdString();
205 Xapian::PostingIterator p = mDb->postlist_begin(id);
206 if (p != mDb->postlist_end(id)) {
207 auto document = mDb->get_document(*p);
208 QStringList terms;
209 for (auto it = document.termlist_begin(); it != document.termlist_end(); it++) {
210 terms << QString::fromStdString(*it);
211 }
212 return {true, terms};
213 }
214 } catch (const Xapian::Error &) {
215 // Nothing to do, move along
216 }
217 return {};
218}