summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r--sinksh/syntax_modules/sink_inspect.cpp37
1 files changed, 11 insertions, 26 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp
index 1a964cf..e0e30c7 100644
--- a/sinksh/syntax_modules/sink_inspect.cpp
+++ b/sinksh/syntax_modules/sink_inspect.cpp
@@ -17,9 +17,6 @@
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */ 18 */
19 19
20//xapian.h needs to be included first to build
21#include <xapian.h>
22
23#include <QDebug> 20#include <QDebug>
24#include <QObject> // tr() 21#include <QObject> // tr()
25#include <QFile> 22#include <QFile>
@@ -33,6 +30,7 @@
33#include "common/entitybuffer.h" 30#include "common/entitybuffer.h"
34#include "common/metadata_generated.h" 31#include "common/metadata_generated.h"
35#include "common/bufferutils.h" 32#include "common/bufferutils.h"
33#include "common/fulltextindex.h"
36 34
37#include "sinksh_utils.h" 35#include "sinksh_utils.h"
38#include "state.h" 36#include "state.h"
@@ -120,32 +118,19 @@ bool inspect(const QStringList &args, State &state)
120 return false; 118 return false;
121 } 119 }
122 if (options.options.contains("fulltext")) { 120 if (options.options.contains("fulltext")) {
123 try { 121 FulltextIndex index(resource, Sink::Storage::DataStore::ReadOnly);
124 Xapian::Database db(QFile::encodeName(Sink::resourceStorageLocation(resource) + '/' + "fulltext").toStdString(), Xapian::DB_OPEN); 122 if (options.options.value("fulltext").isEmpty()) {
125 if (options.options.value("fulltext").isEmpty()) { 123 state.printLine(QString("Total document count: ") + QString::number(index.getDoccount()));
126 state.printLine(QString("Total document count: ") + QString::number(db.get_doccount())); 124 } else {
125 const auto entityId = SinkshUtils::parseUid(options.options.value("fulltext").first().toUtf8());
126 const auto content = index.getIndexContent(entityId);
127 if (!content.found) {
128 state.printLine(QString("Failed to find the document with the id: ") + entityId);
127 } else { 129 } else {
128 auto entityId = SinkshUtils::parseUid(options.options.value("fulltext").first().toUtf8()); 130 state.printLine(QString("Found document with terms: ") + content.terms.join(", "), 1);
129 auto id = "Q" + entityId.toStdString();
130 Xapian::PostingIterator p = db.postlist_begin(id);
131 if (p == db.postlist_end(id)) {
132 state.printLine(QString("Failed to find the document with the id: ") + QString::fromStdString(id));
133 } else {
134 state.printLine(QString("Found the document: "));
135 auto document = db.get_document(*p);
136
137 QStringList terms;
138 for (auto it = document.termlist_begin(); it != document.termlist_end(); it++) {
139 terms << QString::fromStdString(*it);
140 }
141 state.printLine(QString("Terms: ") + terms.join(", "), 1);
142 }
143
144 } 131 }
145 } catch (const Xapian::Error &) {
146 // Nothing to do, move along
147 }
148 132
133 }
149 return false; 134 return false;
150 } 135 }
151 136