summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules/sink_inspect.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-02-13 12:04:52 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-02-13 12:08:05 +0100
commitb093ffda77ee716763496be552b06cee5cb1b4e5 (patch)
treeccc74ae5144575b51649077ad18358e7fe58b491 /sinksh/syntax_modules/sink_inspect.cpp
parent6051c1247cde61bcc8e483eb4166e5a297c0ecc6 (diff)
downloadsink-b093ffda77ee716763496be552b06cee5cb1b4e5.tar.gz
sink-b093ffda77ee716763496be552b06cee5cb1b4e5.zip
Added some fulltext index inspection
Diffstat (limited to 'sinksh/syntax_modules/sink_inspect.cpp')
-rw-r--r--sinksh/syntax_modules/sink_inspect.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp
index f75b59f..efa5bb4 100644
--- a/sinksh/syntax_modules/sink_inspect.cpp
+++ b/sinksh/syntax_modules/sink_inspect.cpp
@@ -17,8 +17,12 @@
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
20#include <QDebug> 23#include <QDebug>
21#include <QObject> // tr() 24#include <QObject> // tr()
25#include <QFile>
22 26
23#include "common/resource.h" 27#include "common/resource.h"
24#include "common/storage.h" 28#include "common/storage.h"
@@ -40,7 +44,7 @@ namespace SinkInspect
40bool inspect(const QStringList &args, State &state) 44bool inspect(const QStringList &args, State &state)
41{ 45{
42 if (args.isEmpty()) { 46 if (args.isEmpty()) {
43 state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type])")); 47 state.printError(QObject::tr("Options: [--resource $resource] ([--db $db] [--filter $id] [--showinternal] | [--validaterids $type] | [--fulltext [$id]])"));
44 } 48 }
45 auto options = SyntaxTree::parseOptions(args); 49 auto options = SyntaxTree::parseOptions(args);
46 auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8()); 50 auto resource = SinkshUtils::parseUid(options.options.value("resource").value(0).toUtf8());
@@ -48,8 +52,7 @@ bool inspect(const QStringList &args, State &state)
48 Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); 52 Sink::Storage::DataStore storage(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly);
49 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly); 53 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly);
50 54
51 bool validateRids = options.options.contains("validaterids"); 55 if (options.options.contains("validaterids")) {
52 if (validateRids) {
53 if (options.options.value("validaterids").isEmpty()) { 56 if (options.options.value("validaterids").isEmpty()) {
54 state.printError(QObject::tr("Specify a type to validate.")); 57 state.printError(QObject::tr("Specify a type to validate."));
55 return false; 58 return false;
@@ -116,6 +119,35 @@ bool inspect(const QStringList &args, State &state)
116 119
117 return false; 120 return false;
118 } 121 }
122 if (options.options.contains("fulltext")) {
123 try {
124 Xapian::Database db(QFile::encodeName(Sink::resourceStorageLocation(resource) + '/' + "fulltext").toStdString(), Xapian::DB_OPEN);
125 if (options.options.value("fulltext").isEmpty()) {
126 state.printLine(QString("Total document count: ") + QString::number(db.get_doccount()));
127 } else {
128 auto entityId = SinkshUtils::parseUid(options.options.value("fulltext").first().toUtf8());
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 }
145 } catch (const Xapian::Error &error) {
146 // Nothing to do, move along
147 }
148
149 return false;
150 }
119 151
120 auto dbs = options.options.value("db"); 152 auto dbs = options.options.value("db");
121 auto idFilter = options.options.value("filter"); 153 auto idFilter = options.options.value("filter");