diff options
Diffstat (limited to 'common/fulltextindex.cpp')
-rw-r--r-- | common/fulltextindex.cpp | 34 |
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 | ||
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 | } | ||