small cleanups and comments
This commit is contained in:
parent
5166fc38cf
commit
9029cb92ce
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#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
|
#endif
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -79,16 +79,18 @@ Db *Query::whatDb()
|
|||||||
bool Query::setQuery(RefCntr<SearchData> sdata, int opts,
|
bool Query::setQuery(RefCntr<SearchData> sdata, int opts,
|
||||||
const string& stemlang)
|
const string& stemlang)
|
||||||
{
|
{
|
||||||
|
LOGDEB(("Query::setQuery:\n"));
|
||||||
|
|
||||||
if (!m_db || ISNULL(m_nq)) {
|
if (!m_db || ISNULL(m_nq)) {
|
||||||
LOGERR(("Query::setQuery: not initialised!\n"));
|
LOGERR(("Query::setQuery: not initialised!\n"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_reason.erase();
|
m_reason.erase();
|
||||||
LOGDEB(("Query::setQuery:\n"));
|
|
||||||
|
|
||||||
m_filterTopDir = sdata->getTopdir();
|
m_filterTopDir = sdata->getTopdir();
|
||||||
deleteZ(m_nq->decider);
|
m_qOpts = opts;
|
||||||
deleteZ(m_nq->postfilter);
|
m_nq->clear();
|
||||||
|
|
||||||
if (!m_filterTopDir.empty()) {
|
if (!m_filterTopDir.empty()) {
|
||||||
#if XAPIAN_FILTERING
|
#if XAPIAN_FILTERING
|
||||||
m_nq->decider =
|
m_nq->decider =
|
||||||
@ -97,12 +99,9 @@ bool Query::setQuery(RefCntr<SearchData> sdata, int opts,
|
|||||||
#endif
|
#endif
|
||||||
new FilterMatcher(m_filterTopDir);
|
new FilterMatcher(m_filterTopDir);
|
||||||
}
|
}
|
||||||
m_nq->m_dbindices.clear();
|
|
||||||
m_qOpts = opts;
|
|
||||||
m_nq->termfreqs.clear();
|
|
||||||
Xapian::Query xq;
|
Xapian::Query xq;
|
||||||
if (!sdata->toNativeQuery(*m_db, &xq,
|
if (!sdata->toNativeQuery(*m_db, &xq, (opts & QO_STEM) ? stemlang : "")) {
|
||||||
(opts & QO_STEM) ? stemlang : "")) {
|
|
||||||
m_reason += sdata->getReason();
|
m_reason += sdata->getReason();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -110,7 +109,6 @@ bool Query::setQuery(RefCntr<SearchData> sdata, int opts,
|
|||||||
string ermsg;
|
string ermsg;
|
||||||
string d;
|
string d;
|
||||||
try {
|
try {
|
||||||
delete m_nq->enquire;
|
|
||||||
m_nq->enquire = new Xapian::Enquire(m_db->m_ndb->db);
|
m_nq->enquire = new Xapian::Enquire(m_db->m_ndb->db);
|
||||||
m_nq->enquire->set_query(m_nq->query);
|
m_nq->enquire->set_query(m_nq->query);
|
||||||
m_nq->mset = Xapian::MSet();
|
m_nq->mset = Xapian::MSet();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#ifndef _rclquery_h_included_
|
#ifndef _rclquery_h_included_
|
||||||
#define _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
|
* 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
|
* 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
|
* An Rcl::Query is a question (SearchData) applied to a
|
||||||
* database. Handles access to the results. Somewhat equivalent to a
|
* database. Handles access to the results. Somewhat equivalent to a
|
||||||
* cursor in an rdb.
|
* cursor in an rdb.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class Query {
|
class Query {
|
||||||
public:
|
public:
|
||||||
enum QueryOpts {QO_NONE=0, QO_STEM = 1};
|
enum QueryOpts {QO_NONE=0, QO_STEM = 1};
|
||||||
|
|
||||||
|
/** The constructor only allocates memory */
|
||||||
Query(Db *db);
|
Query(Db *db);
|
||||||
|
|
||||||
~Query();
|
~Query();
|
||||||
|
|
||||||
/** Get explanation about last error */
|
/** Get explanation about last error */
|
||||||
string getReason() const;
|
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,
|
bool setQuery(RefCntr<SearchData> q, int opts = QO_NONE,
|
||||||
const string& stemlang = "english");
|
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 */
|
/** Get results count for current query */
|
||||||
int getResCnt();
|
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();
|
Db *whatDb();
|
||||||
|
|
||||||
/** make this public for access from embedded Db::Native */
|
/* make this public for access from embedded Db::Native */
|
||||||
class Native;
|
class Native;
|
||||||
Native *m_nq;
|
Native *m_nq;
|
||||||
|
|
||||||
@ -79,7 +88,7 @@ private:
|
|||||||
string m_reason; // Error explanation
|
string m_reason; // Error explanation
|
||||||
Db *m_db;
|
Db *m_db;
|
||||||
unsigned int m_qOpts;
|
unsigned int m_qOpts;
|
||||||
/* Copyconst and assignemt private and forbidden */
|
/* Copyconst and assignement private and forbidden */
|
||||||
Query(const Query &) {}
|
Query(const Query &) {}
|
||||||
Query & operator=(const Query &) {return *this;};
|
Query & operator=(const Query &) {return *this;};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#ifndef _rclquery_p_h_included_
|
#ifndef _rclquery_p_h_included_
|
||||||
#define _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 <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -15,11 +15,15 @@ namespace Rcl {
|
|||||||
|
|
||||||
class Query::Native {
|
class Query::Native {
|
||||||
public:
|
public:
|
||||||
Xapian::Query query; // query descriptor: terms and subqueries
|
/** The query I belong to */
|
||||||
// joined by operators (or/and etc...)
|
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
|
/** In case there is a postq filter: sequence of db indices that match */
|
||||||
// db indices that match
|
vector<int> m_dbindices;
|
||||||
|
|
||||||
// Filtering results on location. There are 2 possible approaches
|
// Filtering results on location. There are 2 possible approaches
|
||||||
// for this:
|
// for this:
|
||||||
@ -39,26 +43,27 @@ public:
|
|||||||
// Which is used is decided in SetQuery(), by setting either of
|
// Which is used is decided in SetQuery(), by setting either of
|
||||||
// the two following members. This in turn is controlled by a
|
// the two following members. This in turn is controlled by a
|
||||||
// preprocessor directive.
|
// preprocessor directive.
|
||||||
|
|
||||||
#define XAPIAN_FILTERING 1
|
#define XAPIAN_FILTERING 1
|
||||||
|
|
||||||
Xapian::MatchDecider *decider; // Xapian does the filtering
|
Xapian::MatchDecider *decider; // Xapian does the filtering
|
||||||
Xapian::MatchDecider *postfilter; // Result filtering done by Recoll
|
Xapian::MatchDecider *postfilter; // Result filtering done by Recoll
|
||||||
|
|
||||||
Xapian::Enquire *enquire; // Open query descriptor.
|
Xapian::Enquire *enquire; // Open query descriptor.
|
||||||
Xapian::MSet mset; // Partial result set
|
Xapian::MSet mset; // Partial result set
|
||||||
Query *m_q;
|
|
||||||
// Term frequencies for current query. See makeAbstract, setQuery
|
// Term frequencies for current query. See makeAbstract, setQuery
|
||||||
map<string, double> termfreqs;
|
map<string, double> termfreqs;
|
||||||
|
|
||||||
Native(Query *q)
|
Native(Query *q)
|
||||||
: decider(0), postfilter(0), enquire(0), m_q(q)
|
: m_q(q), decider(0), postfilter(0), enquire(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
~Native() {
|
~Native() {
|
||||||
delete decider;
|
clear();
|
||||||
delete postfilter;
|
}
|
||||||
delete enquire;
|
void clear() {
|
||||||
|
m_dbindices.clear();
|
||||||
|
delete decider; decider = 0;
|
||||||
|
delete postfilter; postfilter = 0;
|
||||||
|
delete enquire; enquire = 0;
|
||||||
|
termfreqs.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user