From 9029cb92ce40bd429250a212e28a1f0f944ff50a Mon Sep 17 00:00:00 2001 From: dockes Date: Tue, 1 Jul 2008 08:31:08 +0000 Subject: [PATCH] small cleanups and comments --- src/rcldb/rclquery.cpp | 18 ++++++++---------- src/rcldb/rclquery.h | 35 ++++++++++++++++++++++------------- src/rcldb/rclquery_p.h | 31 ++++++++++++++++++------------- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/rcldb/rclquery.cpp b/src/rcldb/rclquery.cpp index 4c5aee41..34b5e711 100644 --- a/src/rcldb/rclquery.cpp +++ b/src/rcldb/rclquery.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.1 2008-06-13 18:22:46 dockes Exp $ (C) 2008 J.F.Dockes"; +static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.2 2008-07-01 08:31:08 dockes Exp $ (C) 2008 J.F.Dockes"; #endif #include @@ -79,16 +79,18 @@ Db *Query::whatDb() bool Query::setQuery(RefCntr sdata, int opts, const string& stemlang) { + LOGDEB(("Query::setQuery:\n")); + if (!m_db || ISNULL(m_nq)) { LOGERR(("Query::setQuery: not initialised!\n")); return false; } m_reason.erase(); - LOGDEB(("Query::setQuery:\n")); m_filterTopDir = sdata->getTopdir(); - deleteZ(m_nq->decider); - deleteZ(m_nq->postfilter); + m_qOpts = opts; + m_nq->clear(); + if (!m_filterTopDir.empty()) { #if XAPIAN_FILTERING m_nq->decider = @@ -97,12 +99,9 @@ bool Query::setQuery(RefCntr sdata, int opts, #endif new FilterMatcher(m_filterTopDir); } - m_nq->m_dbindices.clear(); - m_qOpts = opts; - m_nq->termfreqs.clear(); + Xapian::Query xq; - if (!sdata->toNativeQuery(*m_db, &xq, - (opts & QO_STEM) ? stemlang : "")) { + if (!sdata->toNativeQuery(*m_db, &xq, (opts & QO_STEM) ? stemlang : "")) { m_reason += sdata->getReason(); return false; } @@ -110,7 +109,6 @@ bool Query::setQuery(RefCntr sdata, int opts, string ermsg; string d; try { - delete m_nq->enquire; m_nq->enquire = new Xapian::Enquire(m_db->m_ndb->db); m_nq->enquire->set_query(m_nq->query); m_nq->mset = Xapian::MSet(); diff --git a/src/rcldb/rclquery.h b/src/rcldb/rclquery.h index bb801c7b..f78dc077 100644 --- a/src/rcldb/rclquery.h +++ b/src/rcldb/rclquery.h @@ -1,6 +1,6 @@ #ifndef _rclquery_h_included_ #define _rclquery_h_included_ -/* @(#$Id: rclquery.h,v 1.1 2008-06-13 18:22:46 dockes Exp $ (C) 2008 J.F.Dockes */ +/* @(#$Id: rclquery.h,v 1.2 2008-07-01 08:31:08 dockes Exp $ (C) 2008 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 @@ -41,36 +41,45 @@ class Doc; * An Rcl::Query is a question (SearchData) applied to a * database. Handles access to the results. Somewhat equivalent to a * cursor in an rdb. + * */ class Query { public: enum QueryOpts {QO_NONE=0, QO_STEM = 1}; + /** The constructor only allocates memory */ Query(Db *db); - ~Query(); /** Get explanation about last error */ string getReason() const; - /** Parse query string and initialize query */ + /** Accept data describing the search and query the index. This can + * be called repeatedly on the same object which gets reinitialized each + * time + */ bool setQuery(RefCntr q, int opts = QO_NONE, const string& stemlang = "english"); - bool getQueryTerms(list& terms); - bool getMatchTerms(const Doc& doc, list& terms); - - /** Get document at rank i in current query. */ - bool getDoc(int i, Doc &doc, int *percent = 0); - - /** Expand query */ - list expand(const Doc &doc); /** Get results count for current query */ int getResCnt(); + /** Get document at rank i in current query results. */ + bool getDoc(int i, Doc &doc, int *percent = 0); + + /** Get possibly expanded list of query terms */ + bool getQueryTerms(list& terms); + + /** Return a list of terms which matched for a specific result document */ + bool getMatchTerms(const Doc& doc, list& terms); + + /** Expand query to look for documents like the one passed in */ + list expand(const Doc &doc); + + /** Return the Db we're set for */ Db *whatDb(); - /** make this public for access from embedded Db::Native */ + /* make this public for access from embedded Db::Native */ class Native; Native *m_nq; @@ -79,7 +88,7 @@ private: string m_reason; // Error explanation Db *m_db; unsigned int m_qOpts; - /* Copyconst and assignemt private and forbidden */ + /* Copyconst and assignement private and forbidden */ Query(const Query &) {} Query & operator=(const Query &) {return *this;}; }; diff --git a/src/rcldb/rclquery_p.h b/src/rcldb/rclquery_p.h index 7f666829..19c61033 100644 --- a/src/rcldb/rclquery_p.h +++ b/src/rcldb/rclquery_p.h @@ -1,6 +1,6 @@ #ifndef _rclquery_p_h_included_ #define _rclquery_p_h_included_ -/* @(#$Id: rclquery_p.h,v 1.1 2008-06-13 18:22:46 dockes Exp $ (C) 2007 J.F.Dockes */ +/* @(#$Id: rclquery_p.h,v 1.2 2008-07-01 08:31:08 dockes Exp $ (C) 2007 J.F.Dockes */ #include #include @@ -15,11 +15,15 @@ namespace Rcl { class Query::Native { public: - Xapian::Query query; // query descriptor: terms and subqueries - // joined by operators (or/and etc...) + /** The query I belong to */ + Query *m_q; + /** query descriptor: terms and subqueries joined by operators + * (or/and etc...) + */ + Xapian::Query query; - vector m_dbindices; // In case there is a postq filter: sequence of - // db indices that match + /** In case there is a postq filter: sequence of db indices that match */ + vector m_dbindices; // Filtering results on location. There are 2 possible approaches // for this: @@ -39,26 +43,27 @@ public: // Which is used is decided in SetQuery(), by setting either of // the two following members. This in turn is controlled by a // preprocessor directive. - #define XAPIAN_FILTERING 1 - Xapian::MatchDecider *decider; // Xapian does the filtering Xapian::MatchDecider *postfilter; // Result filtering done by Recoll Xapian::Enquire *enquire; // Open query descriptor. Xapian::MSet mset; // Partial result set - Query *m_q; // Term frequencies for current query. See makeAbstract, setQuery map termfreqs; Native(Query *q) - : decider(0), postfilter(0), enquire(0), m_q(q) + : m_q(q), decider(0), postfilter(0), enquire(0) { } - ~Native() { - delete decider; - delete postfilter; - delete enquire; + clear(); + } + void clear() { + m_dbindices.clear(); + delete decider; decider = 0; + delete postfilter; postfilter = 0; + delete enquire; enquire = 0; + termfreqs.clear(); } };