From d54ddc61b52678c115b21f3007a921c3eff6d630 Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 7 Dec 2006 16:38:24 +0000 Subject: [PATCH] removed qtry and merged qxtry into xadump --- src/query/Makefile | 10 --- src/query/qtry.cpp | 151 ------------------------------------------- src/query/qxtry.cpp | 127 ------------------------------------ src/query/xadump.cpp | 37 ++++++++++- 4 files changed, 34 insertions(+), 291 deletions(-) delete mode 100644 src/query/qtry.cpp delete mode 100644 src/query/qxtry.cpp diff --git a/src/query/Makefile b/src/query/Makefile index 98c4b4a7..2dbbae12 100644 --- a/src/query/Makefile +++ b/src/query/Makefile @@ -14,16 +14,6 @@ xadump : $(XADUMP_OBJS) $(CXX) $(ALL_CXXFLAGS) -o xadump $(XADUMP_OBJS) \ $(LIBICONV) $(LIBXAPIAN) $(LIBSYS) -QXTRY_OBJS= qxtry.o $(BIGLIB) -qxtry : $(QXTRY_OBJS) - $(CXX) $(ALL_CXXFLAGS) -o qxtry $(QXTRY_OBJS) \ - $(LIBICONV) $(LIBXAPIAN) - -QTRY_OBJS= qtry.o $(BIGLIB) $(MIMELIB) -qtry : $(QTRY_OBJS) - $(CXX) $(ALL_CXXFLAGS) -o qtry $(QTRY_OBJS) \ - $(LIBICONV) $(LIBXAPIAN) - HISTORY_OBJS= trhist.o $(BIGLIB) $(MIMELIB) trhist : $(HISTORY_OBJS) $(CXX) $(ALL_CXXFLAGS) -o trhist $(HISTORY_OBJS) \ diff --git a/src/query/qtry.cpp b/src/query/qtry.cpp deleted file mode 100644 index 4be5973f..00000000 --- a/src/query/qtry.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#ifndef lint -static char rcsid[] = "@(#$Id: qtry.cpp,v 1.8 2006-04-28 07:54:38 dockes Exp $ (C) 2004 J.F.Dockes"; -#endif -/* - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -// Tests with the query interface - -#include - -#include -#include -#include - -#include "conftree.h" -#include "rclconfig.h" -#include "rcldb.h" -#include "transcode.h" -#include "mimehandler.h" -#include "pathut.h" - -#ifndef NO_NAMESPACES -using namespace std; -#endif /* NO_NAMESPACES */ - -#include "rcldb.h" - -static string thisprog; - -static string usage = - " -d -e term [term] ..." - " \n\n" - ; - -static void -Usage(void) -{ - cerr << thisprog << ": usage:\n" << usage; - exit(1); -} - -static int op_flags; -#define OPT_e 0x2 - -int main(int argc, char **argv) -{ - string encoding = "ISO8859-1"; - - thisprog = argv[0]; - argc--; argv++; - - while (argc > 0 && **argv == '-') { - (*argv)++; - if (!(**argv)) - /* Cas du "adb - core" */ - Usage(); - while (**argv) - switch (*(*argv)++) { - case 'e': op_flags |= OPT_e; if (argc < 2) Usage(); - encoding = *(++argv); - argc--; - goto b1; - default: Usage(); break; - } - b1: argc--; argv++; - } - if (argc < 1) - Usage(); - - RclConfig *rclconfig = new RclConfig; - - if (!rclconfig->ok()) - cerr << "Config could not be built" << endl; - - string dbdir = rclconfig->getDbDir(); - if (dbdir.empty()) { - cerr << "No database directory in configuration" << endl; - exit(1); - } - - Rcl::Db *rcldb = new Rcl::Db; - - if (!rcldb->open(dbdir, Rcl::Db::DbRO)) { - fprintf(stderr, "Could not open database\n"); - exit(1); - } - - // TOBEDONE: query syntax. Yes it's mighty stupid to cat terms. - string query; - while (argc--) - query += string(*argv++) + " " ; - rcldb->setQuery(query); - int i = 0; - Rcl::Doc doc; - for (i=0;;i++) { - doc.erase(); - if (!rcldb->getDoc(i, doc)) - break; - - cout << "Url: " << doc.url << endl; - cout << "Mimetype: " << doc.mimetype << endl; - cout << "fmtime: " << doc.fmtime << endl; - cout << "dmtime: " << doc.dmtime << endl; - cout << "Origcharset: " << doc.origcharset << endl; - cout << "Title: " << doc.title << endl; - cout << "Text: " << doc.text << endl; - cout << "Keywords: " << doc.keywords << endl; - cout << "Abstract: " << doc.abstract << endl; - cout << endl; - - // Go to the file system to retrieve / convert the document text - // for preview: - - // Look for appropriate handler - MimeHandler *fun = getMimeHandler(doc.mimetype, rclconfig); - if (!fun) { - cout << "No mime handler !" << endl; - continue; - } - string fn = doc.url.substr(6, string::npos); - cout << "Filename: " << fn << endl; - - Rcl::Doc fdoc; - if (fun->mkDoc(rclconfig, fn, doc.mimetype, fdoc, doc.ipath) == - MimeHandler::MHError) { - cout << "Failed to convert/preview document!" << endl; - continue; - } - string outencoding = "iso8859-1"; - string printable; - transcode(fdoc.text, printable, "UTF-8", outencoding); - cout << printable << endl; - } - delete rcldb; - cerr << "Exiting" << endl; - exit(0); -} diff --git a/src/query/qxtry.cpp b/src/query/qxtry.cpp deleted file mode 100644 index 112773a2..00000000 --- a/src/query/qxtry.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef lint -static char rcsid[] = "@(#$Id: qxtry.cpp,v 1.3 2006-01-23 13:32:28 dockes Exp $ (C) 2004 J.F.Dockes"; -#endif -/* - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -// Tests with direct xapian questions - -#include - -#include -#include -#include - -#include "transcode.h" - -#ifndef NO_NAMESPACES -using namespace std; -#endif /* NO_NAMESPACES */ - -#include "xapian.h" - -static string thisprog; - -static string usage = - " -d -e term [term] ..." - " \n\n" - ; - -static void -Usage(void) -{ - cerr << thisprog << ": usage:\n" << usage; - exit(1); -} - -static int op_flags; -#define OPT_d 0x1 -#define OPT_e 0x2 - -Xapian::Database db; - -int main(int argc, char **argv) -{ - string dbdir = "/home/dockes/tmp/xapiandb"; - string encoding = "ISO8859-1"; - - thisprog = argv[0]; - argc--; argv++; - - while (argc > 0 && **argv == '-') { - (*argv)++; - if (!(**argv)) - /* Cas du "adb - core" */ - Usage(); - while (**argv) - switch (*(*argv)++) { - case 'd': op_flags |= OPT_e; if (argc < 2) Usage(); - dbdir = *(++argv); - argc--; - goto b1; - case 'e': op_flags |= OPT_d; if (argc < 2) Usage(); - encoding = *(++argv); - argc--; - goto b1; - default: Usage(); break; - } - b1: argc--; argv++; - } - if (argc < 1) - Usage(); - - vector qterms; - while (argc--) { - qterms.push_back(*argv++); - } - - try { - db = Xapian::Auto::open(dbdir, Xapian::DB_OPEN); - - cout << "DB: ndocs " << db.get_doccount() << " lastdocid " << - db.get_lastdocid() << " avglength " << db.get_avlength() << endl; - - Xapian::Enquire enquire(db); - - Xapian::Query query(Xapian::Query::OP_OR, qterms.begin(), - qterms.end()); - cout << "Performing query `" << - query.get_description() << "'" << endl; - enquire.set_query(query); - - Xapian::MSet matches = enquire.get_mset(0, 10); - cout << "Estimated results: " << matches.get_matches_lower_bound() << - endl; - Xapian::MSetIterator i; - for (i = matches.begin(); i != matches.end(); ++i) { - cout << "Document ID " << *i << "\t"; - cout << i.get_percent() << "% "; - Xapian::Document doc = i.get_document(); - cout << "[" << doc.get_data() << "]" << endl; - } - - } catch (const Xapian::Error &e) { - cout << "Exception: " << e.get_msg() << endl; - } catch (const string &s) { - cout << "Exception: " << s << endl; - } catch (const char *s) { - cout << "Exception: " << s << endl; - } catch (...) { - cout << "Caught unknown exception" << endl; - } - - exit(0); -} diff --git a/src/query/xadump.cpp b/src/query/xadump.cpp index 63c3f28c..3c2d8954 100644 --- a/src/query/xadump.cpp +++ b/src/query/xadump.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: xadump.cpp,v 1.12 2006-12-01 10:05:15 dockes Exp $ (C) 2004 J.F.Dockes"; +static char rcsid[] = "@(#$Id: xadump.cpp,v 1.13 2006-12-07 16:38:24 dockes Exp $ (C) 2004 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -45,6 +45,7 @@ static string usage = " -T : list all terms\n" " -f : precede each term in the list with its occurrence count\n" " -s : special mode to dump recoll stem db\n" + " -q term [term ...] : perform AND query\n" " \n\n" ; @@ -68,6 +69,7 @@ static int op_flags; #define OPT_b 0x200 #define OPT_s 0x400 #define OPT_f 0x800 +#define OPT_q 0x1000 Xapian::Database *db; @@ -118,6 +120,7 @@ int main(int argc, char **argv) argc--; goto b1; case 'P': op_flags |= OPT_P; break; + case 'q': op_flags |= OPT_q; break; case 's': op_flags |= OPT_s; break; case 'T': op_flags |= OPT_T; break; case 't': op_flags |= OPT_t; if (argc < 2) Usage(); @@ -129,8 +132,20 @@ int main(int argc, char **argv) b1: argc--; argv++; } + vector qterms; + if (op_flags & OPT_q) { + fprintf(stderr, "q argc %d\n", argc); + if (argc < 1) + Usage(); + while (argc > 0) { + qterms.push_back(*argv++); argc--; + } + } + + fprintf(stderr, "argc %d\n", argc); if (argc != 0) Usage(); + atexit(cleanup); if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, sigcleanup); @@ -218,10 +233,26 @@ int main(int argc, char **argv) } else if (op_flags & OPT_E) { cout << "Exists [" << aterm << "] : " << db->term_exists(aterm) << endl; - } - + } else if (op_flags & OPT_q) { + Xapian::Enquire enquire(*db); + Xapian::Query query(Xapian::Query::OP_AND, qterms.begin(), + qterms.end()); + cout << "Performing query `" << + query.get_description() << "'" << endl; + enquire.set_query(query); + Xapian::MSet matches = enquire.get_mset(0, 10); + cout << "Estimated results: " << + matches.get_matches_lower_bound() << endl; + Xapian::MSetIterator i; + for (i = matches.begin(); i != matches.end(); ++i) { + cout << "Document ID " << *i << "\t"; + cout << i.get_percent() << "% "; + Xapian::Document doc = i.get_document(); + cout << "[" << doc.get_data() << "]" << endl; + } + } } catch (const Xapian::Error &e) { cout << "Exception: " << e.get_msg() << endl; } catch (const string &s) {