added field/prefixes for author and title + command line query language

This commit is contained in:
dockes
2007-01-17 13:53:41 +00:00
parent ee85be5c61
commit 1d683ad411
15 changed files with 256 additions and 105 deletions
+20 -5
View File
@@ -1,11 +1,11 @@
depth = ..
include $(depth)/mk/sysconf
PROGS = xadump #trhist qtry qxtry
PROGS = xadump rclqlang #trhist qtry qxtry
all: $(PROGS)
SRCS = xadump.cpp
SRCS = xadump.cpp rclqlang.cpp
.cpp.o :
$(CXX) -c $(ALL_CXXFLAGS) -o $@ $<
@@ -14,6 +14,11 @@ xadump : $(XADUMP_OBJS)
$(CXX) $(ALL_CXXFLAGS) -o xadump $(XADUMP_OBJS) \
$(LIBICONV) $(LIBXAPIAN) $(LIBSYS)
RCLQLANG_OBJS= rclqlang.o $(BIGLIB)
rclqlang : $(RCLQLANG_OBJS)
$(CXX) $(ALL_CXXFLAGS) -o rclqlang $(RCLQLANG_OBJS) \
$(LIBICONV) $(LIBXAPIAN) $(LIBSYS)
HISTORY_OBJS= trhist.o $(BIGLIB) $(MIMELIB)
trhist : $(HISTORY_OBJS)
$(CXX) $(ALL_CXXFLAGS) -o trhist $(HISTORY_OBJS) \
@@ -21,9 +26,19 @@ trhist : $(HISTORY_OBJS)
trhist.o : history.cpp history.h
$(CXX) $(ALL_CXXFLAGS) -DTEST_HISTORY -c -o trhist.o history.cpp
$(BIGLIB):
cd $(depth)/lib;make
WASASTRINGTOQUERY_OBJS= trwasastrtoq.o $(BIGLIB) $(MIMELIB)
trwasastrtoq : $(WASASTRINGTOQUERY_OBJS)
$(CXX) $(ALL_CXXFLAGS) -o trwasastrtoq $(WASASTRINGTOQUERY_OBJS) \
$(LIBICONV) $(LIBXAPIAN)
trwasastrtoq.o : wasastringtoquery.cpp wasastringtoquery.h
$(CXX) $(ALL_CXXFLAGS) -DTEST_WASASTRINGTOQUERY -c \
-o trwasastrtoq.o wasastringtoquery.cpp
$(BIGLIB): force
cd $(depth)/lib;$(MAKE)
force:
depend: alldeps.stamp
alldeps.stamp : $(SRCS)
$(CXX) -M $(ALL_CXXFLAGS) $(SRCS) > alldeps
+32 -13
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.3 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.4 2007-01-17 13:53:41 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -17,7 +17,7 @@ static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.3 2006-12-10 17:03:08 d
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef TEST_STRINGTOQUERY
#ifndef TEST_WASASTRINGTOQUERY
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -25,6 +25,13 @@ static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.3 2006-12-10 17:03:08 d
#include "wasastringtoquery.h"
//#define DEB_WASASTRINGTOQ 1
#ifdef DEB_WASASTRINGTOQ
#define DPRINT(X) fprintf X
#else
#define DPRINT(X)
#endif
WasaQuery::~WasaQuery()
{
for (vector<WasaQuery*>::iterator it = m_subs.begin();
@@ -61,16 +68,16 @@ void WasaQuery::describe(string &desc) const
desc += ")";
}
desc += "(";
string fieldspec = m_fieldspec.empty() ? "" : m_fieldspec + ": ";
switch (m_op) {
case OP_NULL:
desc += "NULL";
break;
case OP_LEAF:
desc += m_fieldspec.empty() ?
m_value : m_fieldspec + ":" + m_value;
desc += fieldspec + m_value;
break;
case OP_EXCL:
desc += string("NOT (" ) + m_value + ") ";
desc += string("NOT (" ) + fieldspec + m_value + ") ";
break;
case OP_OR:
case OP_AND:
@@ -84,6 +91,8 @@ void WasaQuery::describe(string &desc) const
}
break;
}
if (desc[desc.length() - 1] == ' ')
desc.erase(desc.length() - 1);
desc += ") ";
}
@@ -111,7 +120,7 @@ void WasaQuery::describe(string &desc) const
* parenthesis increases the index, but we're not interested in all
*/
static const char * parserExpr =
"([oO][rR])" //1 OR is a special word
"([oO][rR])[[:space:]]*" //1 OR is a special word
"|"
"(" //2
"([+-])?" //3 Force or exclude indicator
@@ -125,7 +134,7 @@ static const char * parserExpr =
"|"
"([^[:space:]]+)" //9 ANormalTerm
")"
")"
")[[:space:]]*"
;
// For debugging the parser. But see also NMATCH
@@ -236,17 +245,18 @@ StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason)
reason = "Internal regular expression handling error";
return 0;
}
#if 0
if (loop) printf("Next part:\n");
for (i = 0; i < NMATCH; i++) {
#ifdef DEB_WASASTRINGTOQ
if (loop) DPRINT((stderr, "Next part:\n"));
for (unsigned int i = 0; i < NMATCH; i++) {
if (m_pmatch[i].rm_so == -1) continue;
char match[maxmatchlen+1];
memcpy(match, m_cp + m_pmatch[i].rm_so,
m_pmatch[i].rm_eo - m_pmatch[i].rm_so);
match[m_pmatch[i].rm_eo - m_pmatch[i].rm_so] = 0;
if (matchNames[i][0])
printf("%10s: [%s] (%d->%d)\n", matchNames[i], match,
(int)m_pmatch[i].rm_so, (int)m_pmatch[i].rm_eo);
DPRINT((stderr, "%10s: [%s] (%d->%d)\n", matchNames[i], match,
(int)m_pmatch[i].rm_so, (int)m_pmatch[i].rm_eo));
}
#endif
char match[maxmatchlen+1];
@@ -348,14 +358,17 @@ StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason)
if (prev_or) {
// We're in an OR subquery, add new subquery
orClause->m_subs.push_back(nclause);
DPRINT((stderr, "Adding to OR chain\n"));
} else {
if (orClause) {
// Getting out of OR. Add the OR subquery to the main one
query->m_subs.push_back(orClause);
DPRINT((stderr, "Adding OR chain to main\n"));
orClause = 0;
}
// Add new subquery to main one.
query->m_subs.push_back(nclause);
DPRINT((stderr, "Adding to main chain\n"));
}
prev_or = false;
}
@@ -369,6 +382,12 @@ StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason)
break;
}
if (orClause) {
// Getting out of OR. Add the OR subquery to the main one
query->m_subs.push_back(orClause);
DPRINT((stderr, "Adding OR chain to main\n"));
}
regfree(&m_rx);
m_rxneedsfree = false;
return query;
@@ -404,4 +423,4 @@ int main(int argc, char **argv)
exit(0);
}
#endif // TEST_STRINGTOQUERY
#endif // TEST_WASASTRINGTOQUERY
+12 -7
View File
@@ -1,6 +1,6 @@
#ifndef _WASASTRINGTOQUERY_H_INCLUDED_
#define _WASASTRINGTOQUERY_H_INCLUDED_
/* @(#$Id: wasastringtoquery.h,v 1.3 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes */
/* @(#$Id: wasastringtoquery.h,v 1.4 2007-01-17 13:53:41 dockes Exp $ (C) 2006 J.F.Dockes */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,23 +40,28 @@ public:
{}
~WasaQuery();
// Get string describing the query tree from this point
/** Get string describing the query tree from this point */
void describe(string &desc) const;
/** Op to be performed on either value or subqueries */
WasaQuery::Op m_op;
/** Field specification if any (ie: title, author ...) */
string m_fieldspec;
/* Valid for op == OP_LEAF */
/* String value. Valid for op == OP_LEAF */
string m_value;
/* Valid for conjunctions */
/** Subqueries. Valid for conjunctions */
vector<WasaQuery*> m_subs;
/* Restrict results to some file type, defined by either mime, app group,
* or extension */
/** Restrict results to some file type, defined by either mime,
* app group, or extension */
enum TypeKind {WQTK_NONE, WQTK_MIME, WQTK_GROUP, WQTK_EXT};
TypeKind m_typeKind;
vector<string> m_types;
/* Sort on relevance, date, name or group */
/** Sort on relevance, date, name or group */
enum SortKind {WQSK_REL, WQSK_DATE, WQSK_ALPHA, WQSK_GROUP};
vector<SortKind> m_sortSpec;
};
+12 -10
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.2 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.3 2007-01-17 13:53:41 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
#ifndef TEST_WASATORCL
@@ -27,11 +27,13 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
if ((*it)->m_value.find_first_of(" \t\n\r") != string::npos) {
sdata->addClause
(new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
(*it)->m_value, 0));
(*it)->m_value, 0,
(*it)->m_fieldspec));
} else {
sdata->addClause
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
(*it)->m_value));
(*it)->m_value,
(*it)->m_fieldspec));
}
break;
case WasaQuery::OP_EXCL:
@@ -41,7 +43,8 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
sdata->addClause
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
string("\"") +
(*it)->m_value + "\""));
(*it)->m_value + "\"",
(*it)->m_fieldspec));
break;
case WasaQuery::OP_OR:
// Concatenate all OR values as phrases. Hope there are no
@@ -55,7 +58,8 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
}
sdata->addClause
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
orvalue));
orvalue,
(*it)->m_fieldspec));
}
}
}
@@ -105,7 +109,7 @@ int main(int argc, char *argv[])
if (argc != 1) {
fprintf(stderr, "need one arg\n");
exit(1);
return 1;
}
const string str = *argv++;argc--;
string reason;
@@ -113,14 +117,12 @@ int main(int argc, char *argv[])
RclConfig *config = recollinit(RCLINIT_NONE, 0, 0, reason, 0);
if (config == 0 || !config->ok()) {
cerr << "Configuration problem: " << reason << endl;
exit(1);
return 1;
}
string dbdir = config->getDbDir();
if (dbdir.empty()) {
// Note: this will have to be replaced by a call to a
// configuration buildin dialog for initial configuration
cerr << "Configuration problem: " << "No dbdir" << endl;
exit(1);
return 1;
}
Rcl::Db rcldb;
if (!rcldb.open(dbdir, Rcl::Db::DbRO, 0)) {