From 0a6229931ac90fa8914dbdafef51adf5ca92a206 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 27 Jul 2018 12:18:06 +0200 Subject: All xapian stuff in a central place --- common/fulltextindex.cpp | 34 ++++++++++++++++++++++++++++++++++ common/fulltextindex.h | 7 +++++++ 2 files changed, 41 insertions(+) (limited to 'common') 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 FulltextIndex::lookup(const QString &searchTerm) return results; } +qint64 FulltextIndex::getDoccount() const +{ + if (!mDb) { + return -1; + } + try { + return mDb->get_doccount(); + } catch (const Xapian::Error &) { + // Nothing to do, move along + } + return -1; +} + +FulltextIndex::Result FulltextIndex::getIndexContent(const QByteArray &identifier) const +{ + if (!mDb) { + {}; + } + try { + auto id = "Q" + identifier.toStdString(); + Xapian::PostingIterator p = mDb->postlist_begin(id); + if (p != mDb->postlist_end(id)) { + auto document = mDb->get_document(*p); + QStringList terms; + for (auto it = document.termlist_begin(); it != document.termlist_end(); it++) { + terms << QString::fromStdString(*it); + } + return {true, terms}; + } + } catch (const Xapian::Error &) { + // Nothing to do, move along + } + return {}; +} 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: QVector lookup(const QString &key); + qint64 getDoccount() const; + struct Result { + bool found{false}; + QStringList terms; + }; + Result getIndexContent(const QByteArray &identifier) const; + private: Xapian::WritableDatabase* writableDatabase(); Q_DISABLE_COPY(FulltextIndex); -- cgit v1.2.3