query: extract the collapse count from xapian + small cleanups

This commit is contained in:
Jean-Francois Dockes 2011-01-17 11:25:05 +01:00
parent 9b738ebb61
commit 34511918d9
7 changed files with 27 additions and 31 deletions

View File

@ -754,7 +754,7 @@ void RclMain::startPreview(int docnum, Rcl::Doc doc, int mod)
} }
if (curPreview == 0) { if (curPreview == 0) {
HiliteData hdata; HiliteData hdata;
reslist->getTerms(hdata.terms, hdata.groups, hdata.gslks); m_source->getTerms(hdata.terms, hdata.groups, hdata.gslks);
curPreview = new Preview(reslist->listId(), hdata); curPreview = new Preview(reslist->listId(), hdata);
if (curPreview == 0) { if (curPreview == 0) {
@ -1217,12 +1217,16 @@ void RclMain::startManual(const string& index)
// significant terms, and add them to the simple search entry. // significant terms, and add them to the simple search entry.
void RclMain::docExpand(Rcl::Doc doc) void RclMain::docExpand(Rcl::Doc doc)
{ {
LOGDEB(("RclMain::docExpand()\n"));
if (!rcldb) if (!rcldb)
return; return;
list<string> terms; list<string> terms;
terms = reslist->expand(doc);
if (terms.empty()) terms = m_source->expand(doc);
if (terms.empty()) {
LOGDEB(("RclMain::docExpand: no terms\n"));
return; return;
}
// Do we keep the original query. I think we'd better not. // Do we keep the original query. I think we'd better not.
// rcldb->expand is set to keep the original query terms instead. // rcldb->expand is set to keep the original query terms instead.
QString text;// = sSearch->queryText->currentText(); QString text;// = sSearch->queryText->currentText();

View File

@ -336,19 +336,6 @@ void ResList::languageChange()
setWindowTitle(tr("Result list")); setWindowTitle(tr("Result list"));
} }
bool ResList::getTerms(vector<string>& terms,
vector<vector<string> >& groups, vector<int>& gslks)
{
return m_source->getTerms(terms, groups, gslks);
}
list<string> ResList::expand(Rcl::Doc& doc)
{
if (m_source.isNull())
return list<string>();
return m_source->expand(doc);
}
// Get document number from paragraph number // Get document number from paragraph number
int ResList::docnumfromparnum(int par) int ResList::docnumfromparnum(int par)
{ {

View File

@ -42,15 +42,13 @@ class ResList : public QTextBrowser
ResList(QWidget* parent = 0, const char* name = 0); ResList(QWidget* parent = 0, const char* name = 0);
virtual ~ResList(); virtual ~ResList();
// Return document for given docnum. We act as an intermediary to // Return document for given docnum. We mostly act as an
// the docseq here. This has also the side-effect of making the // intermediary to the docseq here, but this has also the
// entry current (visible and highlighted), and only works if the // side-effect of making the entry current (visible and
// num is inside the current page or its immediate neighbours. // highlighted), and only works if the num is inside the current
// page or its immediate neighbours.
bool getDoc(int docnum, Rcl::Doc &); bool getDoc(int docnum, Rcl::Doc &);
bool displayingHistory(); bool displayingHistory();
bool getTerms(vector<string>& terms,
vector<vector<string> >& groups, vector<int>& gslks);
list<string> expand(Rcl::Doc& doc);
int listId() const {return m_listId;} int listId() const {return m_listId;}
public slots: public slots:

View File

@ -35,6 +35,7 @@ namespace Rcl {
const string Doc::keysz("size"); const string Doc::keysz("size");
const string Doc::keysig("sig"); const string Doc::keysig("sig");
const string Doc::keyrr("relevancyrating"); const string Doc::keyrr("relevancyrating");
const string Doc::keycc("collapsecount");
const string Doc::keyabs("abstract"); const string Doc::keyabs("abstract");
const string Doc::keyau("author"); const string Doc::keyau("author");
const string Doc::keytt("title"); const string Doc::keytt("title");

View File

@ -155,6 +155,7 @@ class Doc {
static const string keysz; // dbytes if set else fbytes static const string keysz; // dbytes if set else fbytes
static const string keysig; // sig static const string keysig; // sig
static const string keyrr; // relevancy rating static const string keyrr; // relevancy rating
static const string keycc; // Collapse count
static const string keyabs; // abstract static const string keyabs; // abstract
static const string keyau; // author static const string keyau; // author
static const string keytt; // title static const string keytt; // title

View File

@ -321,12 +321,14 @@ bool Query::getDoc(int xapi, Doc &doc)
Xapian::Document xdoc; Xapian::Document xdoc;
Xapian::docid docid = 0; Xapian::docid docid = 0;
int pc = 0; int pc = 0;
int collapsecount = 0;
string data; string data;
string udi; string udi;
m_reason.erase(); m_reason.erase();
for (int xaptries=0; xaptries < 2; xaptries++) { for (int xaptries=0; xaptries < 2; xaptries++) {
try { try {
xdoc = m_nq->xmset[xapi-first].get_document(); xdoc = m_nq->xmset[xapi-first].get_document();
collapsecount = m_nq->xmset[xapi-first].get_collapse_count();
docid = *(m_nq->xmset[xapi-first]); docid = *(m_nq->xmset[xapi-first]);
pc = m_nq->xmset.convert_to_percent(m_nq->xmset[xapi-first]); pc = m_nq->xmset.convert_to_percent(m_nq->xmset[xapi-first]);
data = xdoc.get_data(); data = xdoc.get_data();
@ -339,8 +341,8 @@ bool Query::getDoc(int xapi, Doc &doc)
if (!udi.empty()) if (!udi.empty())
udi = udi.substr(1); udi = udi.substr(1);
} }
LOGDEB2(("Query::getDoc: %d ms to get udi [%s]\n", chron.millis(), LOGDEB2(("Query::getDoc: %d ms for udi [%s], collapse count %d\n",
udi.c_str())); chron.millis(), udi.c_str(), collapsecount));
break; break;
} catch (Xapian::DatabaseModifiedError &error) { } catch (Xapian::DatabaseModifiedError &error) {
// retry or end of loop // retry or end of loop
@ -355,6 +357,9 @@ bool Query::getDoc(int xapi, Doc &doc)
return false; return false;
} }
doc.meta[Rcl::Doc::keyudi] = udi; doc.meta[Rcl::Doc::keyudi] = udi;
char scc[30];
sprintf(scc, "%d", collapsecount);
doc.meta[Rcl::Doc::keycc] = scc;
// Parse xapian document's data and populate doc fields // Parse xapian document's data and populate doc fields
return m_db->m_ndb->dbDataToRclDoc(docid, data, doc, pc); return m_db->m_ndb->dbDataToRclDoc(docid, data, doc, pc);
@ -362,6 +367,7 @@ bool Query::getDoc(int xapi, Doc &doc)
list<string> Query::expand(const Doc &doc) list<string> Query::expand(const Doc &doc)
{ {
LOGDEB(("Rcl::Query::expand()\n"));
list<string> res; list<string> res;
if (ISNULL(m_nq) || !m_nq->xenquire) { if (ISNULL(m_nq) || !m_nq->xenquire) {
LOGERR(("Query::expand: no query opened\n")); LOGERR(("Query::expand: no query opened\n"));

View File

@ -869,13 +869,12 @@ bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p,
(m_parentSearch && !m_parentSearch->haveWildCards()) || (m_parentSearch && !m_parentSearch->haveWildCards()) ||
(m_parentSearch == 0 && !m_haveWildCards); (m_parentSearch == 0 && !m_haveWildCards);
// We produce a single phrase out of the user entry (there should be // We produce a single phrase out of the user entry then use
// no dquotes in there), then use stringToXapianQueries() to // stringToXapianQueries() to lowercase and simplify the phrase
// lowercase and simplify the phrase terms etc. This will result // terms etc. This will result into a single (complex)
// into a single (complex) Xapian::Query. // Xapian::Query.
if (m_text.find_first_of("\"") != string::npos) { if (m_text.find_first_of("\"") != string::npos) {
LOGDEB(("Double quotes inside phrase/near field\n")); m_text = neutchars(m_text, "\"");
return false;
} }
string s = string("\"") + m_text + string("\""); string s = string("\"") + m_text + string("\"");
bool useNear = (m_tp == SCLT_NEAR); bool useNear = (m_tp == SCLT_NEAR);