small cleanups and comments

This commit is contained in:
dockes 2008-07-01 08:31:08 +00:00
parent 5166fc38cf
commit 9029cb92ce
3 changed files with 48 additions and 36 deletions

View File

@ -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 <list>
@ -79,16 +79,18 @@ Db *Query::whatDb()
bool Query::setQuery(RefCntr<SearchData> 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<SearchData> 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<SearchData> 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();

View File

@ -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<SearchData> q, int opts = QO_NONE,
const string& stemlang = "english");
bool getQueryTerms(list<string>& terms);
bool getMatchTerms(const Doc& doc, list<string>& terms);
/** Get document at rank i in current query. */
bool getDoc(int i, Doc &doc, int *percent = 0);
/** Expand query */
list<string> 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<string>& terms);
/** Return a list of terms which matched for a specific result document */
bool getMatchTerms(const Doc& doc, list<string>& terms);
/** Expand query to look for documents like the one passed in */
list<string> 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;};
};

View File

@ -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 <map>
#include <vector>
@ -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<int> 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<int> 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<string, double> 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();
}
};