From 34511918d9fd8ce54954201e120c8e2bf4b3576b Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 17 Jan 2011 11:25:05 +0100 Subject: [PATCH] query: extract the collapse count from xapian + small cleanups --- src/qtgui/rclmain_w.cpp | 10 +++++++--- src/qtgui/reslist.cpp | 13 ------------- src/qtgui/reslist.h | 12 +++++------- src/rcldb/rcldoc.cpp | 1 + src/rcldb/rcldoc.h | 1 + src/rcldb/rclquery.cpp | 10 ++++++++-- src/rcldb/searchdata.cpp | 11 +++++------ 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index aa8d9a44..dad09c45 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -754,7 +754,7 @@ void RclMain::startPreview(int docnum, Rcl::Doc doc, int mod) } if (curPreview == 0) { 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); if (curPreview == 0) { @@ -1217,12 +1217,16 @@ void RclMain::startManual(const string& index) // significant terms, and add them to the simple search entry. void RclMain::docExpand(Rcl::Doc doc) { + LOGDEB(("RclMain::docExpand()\n")); if (!rcldb) return; list terms; - terms = reslist->expand(doc); - if (terms.empty()) + + terms = m_source->expand(doc); + if (terms.empty()) { + LOGDEB(("RclMain::docExpand: no terms\n")); return; + } // Do we keep the original query. I think we'd better not. // rcldb->expand is set to keep the original query terms instead. QString text;// = sSearch->queryText->currentText(); diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index 7c0581f0..58b5ba5a 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -336,19 +336,6 @@ void ResList::languageChange() setWindowTitle(tr("Result list")); } -bool ResList::getTerms(vector& terms, - vector >& groups, vector& gslks) -{ - return m_source->getTerms(terms, groups, gslks); -} - -list ResList::expand(Rcl::Doc& doc) -{ - if (m_source.isNull()) - return list(); - return m_source->expand(doc); -} - // Get document number from paragraph number int ResList::docnumfromparnum(int par) { diff --git a/src/qtgui/reslist.h b/src/qtgui/reslist.h index cbb2d67b..b2982e45 100644 --- a/src/qtgui/reslist.h +++ b/src/qtgui/reslist.h @@ -42,15 +42,13 @@ class ResList : public QTextBrowser ResList(QWidget* parent = 0, const char* name = 0); virtual ~ResList(); - // Return document for given docnum. We act as an intermediary to - // the docseq here. This has also the side-effect of making the - // entry current (visible and highlighted), and only works if the - // num is inside the current page or its immediate neighbours. + // Return document for given docnum. We mostly act as an + // intermediary to the docseq here, but this has also the + // side-effect of making the entry current (visible and + // highlighted), and only works if the num is inside the current + // page or its immediate neighbours. bool getDoc(int docnum, Rcl::Doc &); bool displayingHistory(); - bool getTerms(vector& terms, - vector >& groups, vector& gslks); - list expand(Rcl::Doc& doc); int listId() const {return m_listId;} public slots: diff --git a/src/rcldb/rcldoc.cpp b/src/rcldb/rcldoc.cpp index 618b8166..05107b7d 100644 --- a/src/rcldb/rcldoc.cpp +++ b/src/rcldb/rcldoc.cpp @@ -35,6 +35,7 @@ namespace Rcl { const string Doc::keysz("size"); const string Doc::keysig("sig"); const string Doc::keyrr("relevancyrating"); + const string Doc::keycc("collapsecount"); const string Doc::keyabs("abstract"); const string Doc::keyau("author"); const string Doc::keytt("title"); diff --git a/src/rcldb/rcldoc.h b/src/rcldb/rcldoc.h index 0dc11ca9..c0f8fb29 100644 --- a/src/rcldb/rcldoc.h +++ b/src/rcldb/rcldoc.h @@ -155,6 +155,7 @@ class Doc { static const string keysz; // dbytes if set else fbytes static const string keysig; // sig static const string keyrr; // relevancy rating + static const string keycc; // Collapse count static const string keyabs; // abstract static const string keyau; // author static const string keytt; // title diff --git a/src/rcldb/rclquery.cpp b/src/rcldb/rclquery.cpp index 2940201f..2db65d60 100644 --- a/src/rcldb/rclquery.cpp +++ b/src/rcldb/rclquery.cpp @@ -321,12 +321,14 @@ bool Query::getDoc(int xapi, Doc &doc) Xapian::Document xdoc; Xapian::docid docid = 0; int pc = 0; + int collapsecount = 0; string data; string udi; m_reason.erase(); for (int xaptries=0; xaptries < 2; xaptries++) { try { xdoc = m_nq->xmset[xapi-first].get_document(); + collapsecount = m_nq->xmset[xapi-first].get_collapse_count(); docid = *(m_nq->xmset[xapi-first]); pc = m_nq->xmset.convert_to_percent(m_nq->xmset[xapi-first]); data = xdoc.get_data(); @@ -339,8 +341,8 @@ bool Query::getDoc(int xapi, Doc &doc) if (!udi.empty()) udi = udi.substr(1); } - LOGDEB2(("Query::getDoc: %d ms to get udi [%s]\n", chron.millis(), - udi.c_str())); + LOGDEB2(("Query::getDoc: %d ms for udi [%s], collapse count %d\n", + chron.millis(), udi.c_str(), collapsecount)); break; } catch (Xapian::DatabaseModifiedError &error) { // retry or end of loop @@ -355,6 +357,9 @@ bool Query::getDoc(int xapi, Doc &doc) return false; } 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 return m_db->m_ndb->dbDataToRclDoc(docid, data, doc, pc); @@ -362,6 +367,7 @@ bool Query::getDoc(int xapi, Doc &doc) list Query::expand(const Doc &doc) { + LOGDEB(("Rcl::Query::expand()\n")); list res; if (ISNULL(m_nq) || !m_nq->xenquire) { LOGERR(("Query::expand: no query opened\n")); diff --git a/src/rcldb/searchdata.cpp b/src/rcldb/searchdata.cpp index ad5bbaa9..efaee7ea 100644 --- a/src/rcldb/searchdata.cpp +++ b/src/rcldb/searchdata.cpp @@ -869,13 +869,12 @@ bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p, (m_parentSearch && !m_parentSearch->haveWildCards()) || (m_parentSearch == 0 && !m_haveWildCards); - // We produce a single phrase out of the user entry (there should be - // no dquotes in there), then use stringToXapianQueries() to - // lowercase and simplify the phrase terms etc. This will result - // into a single (complex) Xapian::Query. + // We produce a single phrase out of the user entry then use + // stringToXapianQueries() to lowercase and simplify the phrase + // terms etc. This will result into a single (complex) + // Xapian::Query. if (m_text.find_first_of("\"") != string::npos) { - LOGDEB(("Double quotes inside phrase/near field\n")); - return false; + m_text = neutchars(m_text, "\""); } string s = string("\"") + m_text + string("\""); bool useNear = (m_tp == SCLT_NEAR);