[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/strigi/src/streamindexer
From: Jos van den Oever <jos () vandenoever ! info>
Date: 2006-06-30 15:05:03
Message-ID: 1151679903.325269.3860.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 556530 by vandenoever:
slight refactoring
M +1 -1 Makefile.am
D indexreader.cpp
M +100 -0 query.cpp
--- trunk/playground/base/strigi/src/streamindexer/Makefile.am #556529:556530
@@ -3,7 +3,7 @@
libstreamindexer_la_SOURCES = bz2endanalyzer.cpp digestthroughanalyzer.cpp \
textendanalyzer.cpp streamendanalyzer.cpp zipendanalyzer.cpp \
tarendanalyzer.cpp streamindexer.cpp pngendanalyzer.cpp query.cpp\
- mailendanalyzer.cpp gzipendanalyzer.cpp filelister.cpp indexreader.cpp \
+ mailendanalyzer.cpp gzipendanalyzer.cpp filelister.cpp \
mimetypethroughanalyzer.cpp pluginthroughanalyzer.cpp indexwriter.cpp \
saxendanalyzer.cpp
--- trunk/playground/base/strigi/src/streamindexer/query.cpp #556529:556530
@@ -2,6 +2,106 @@
using namespace std;
using namespace jstreams;
+/**
+ * The constructor parses the query in include and exclude statements.
+ * The following lines contain example queries.
+ * hi
+ * 'hi'
+ * hi Jos
+ * 'hi Jos'
+ * "hi Jos"
+ * -hi Jos
+ * path:"hi Jos"
+ * -path:"hi Jos"
+ * So the syntax is something like this:
+ * query ::= [term]*
+ * term ::= [-][prefix]:("searchphrase"|searchphrase)
+ **/
+
+Query::Query(const string& query, int max, int offset) {
+ this->max = max;
+ this->offset = offset;
+ const char* q = query.c_str();
+ const char* end = q+query.length();
+ const char* p = q;
+ while (p < end) {
+ p = parseTerm(p);
+ }
+/* map<string, set<string> >::const_iterator i;
+ set<string>::const_iterator j;
+ for (i = includes.begin(); i != includes.end(); ++i) {
+ for (j = i->second.begin(); j != i->second.end(); ++j) {
+ printf("+ '%s':'%s'\n", i->first.c_str(), j->c_str());
+ }
+ }
+ for (i = excludes.begin(); i != excludes.end(); ++i) {
+ for (j = i->second.begin(); j != i->second.end(); ++j) {
+ printf("- '%s':'%s'\n", i->first.c_str(), j->c_str());
+ }
+ }
+ printf("--\n");*/
+}
+const char*
+Query::parseTerm(const char* s) {
+ bool include = true;
+ const char* p = s;
+ // skip whitespace
+ while (*p != '\0' && isspace(*p)) p++;
+ if (*p == '\0') return p;
+
+ // check for a - sign
+ if (*p == '-') {
+ include = false;
+ p++;
+ }
+ // skip whitespace
+ while (*p != '\0' && isspace(*p)) p++;
+ if (*p == '\0') return p;
+
+ char quote = 0;
+ if (*p == '\'' || *p == '"') {
+ quote = *p++;
+ if (*p == '\0') return p;
+ }
+ const char* prefix = 0;
+ const char* prefend;
+ const char* term = p;
+ // skip until end of string or closing quote or colon or whitespace
+ while (*p != '\0' && ((quote == 0 && !isspace(*p))
+ || (quote != 0 && *p != quote))) {
+ if (quote == 0 && *p == ':') {
+ // define the prefix
+ prefix = term;
+ prefend = p;
+ ++p;
+ if (*p == '\0') return p;
+ if (*p == '\'' || *p == '"') {
+ quote = *p++;
+ if (*p == '\0') return p;
+ }
+ term = p;
+ }
+ ++p;
+ }
+ if (*term == '\0') return term;
+ if (p - term > 0) {
+ string pre;
+ string ter;
+ if (prefix != 0 && term - prefix > 1) {
+ pre = string(prefix, prefend-prefix);
+ }
+ ter = string(term, p-term);
+ if (include) {
+ includes[pre].insert(ter);
+ } else {
+ excludes[pre].insert(ter);
+ }
+ }
+ // skip the terminating character
+ if (p != '\0') p++;
+ return p;
+}
+
void
replaceall(string& text, const string& a, const string& b) {
size_t pos = 0;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic