diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-27 12:18:06 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-27 13:15:22 +0200 |
commit | 0a6229931ac90fa8914dbdafef51adf5ca92a206 (patch) | |
tree | 9d4821ecc211842071f023a2465e9a5f4cdb3c7d /common | |
parent | 5e421481b95bc46aae05260e0afc6aa32945e62f (diff) | |
download | sink-0a6229931ac90fa8914dbdafef51adf5ca92a206.tar.gz sink-0a6229931ac90fa8914dbdafef51adf5ca92a206.zip |
All xapian stuff in a central place
Diffstat (limited to 'common')
-rw-r--r-- | common/fulltextindex.cpp | 34 | ||||
-rw-r--r-- | common/fulltextindex.h | 7 |
2 files changed, 41 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 | ||
185 | qint64 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 | |||
198 | FulltextIndex::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 | } | ||
diff --git a/common/fulltextindex.h b/common/fulltextindex.h index e06f29d..f24af3b 100644 --- a/common/fulltextindex.h +++ b/common/fulltextindex.h | |||
@@ -29,6 +29,13 @@ public: | |||
29 | 29 | ||
30 | QVector<QByteArray> lookup(const QString &key); | 30 | QVector<QByteArray> lookup(const QString &key); |
31 | 31 | ||
32 | qint64 getDoccount() const; | ||
33 | struct Result { | ||
34 | bool found{false}; | ||
35 | QStringList terms; | ||
36 | }; | ||
37 | Result getIndexContent(const QByteArray &identifier) const; | ||
38 | |||
32 | private: | 39 | private: |
33 | Xapian::WritableDatabase* writableDatabase(); | 40 | Xapian::WritableDatabase* writableDatabase(); |
34 | Q_DISABLE_COPY(FulltextIndex); | 41 | Q_DISABLE_COPY(FulltextIndex); |