always set the "haspages" flags when reading doc from index so that the Snippets link can be set even if no abstract is computed

This commit is contained in:
Jean-Francois Dockes 2013-05-22 13:24:31 +02:00
parent 493115de49
commit e6402efbfb
4 changed files with 31 additions and 11 deletions

View File

@ -316,6 +316,8 @@ bool Db::Native::dbDataToRclDoc(Xapian::docid docid, std::string &data,
// Set xdocid at once so that we can call whatDbIdx() // Set xdocid at once so that we can call whatDbIdx()
doc.xdocid = docid; doc.xdocid = docid;
doc.haspages = hasPages(docid);
// Compute what index this comes from, and check for path translations // Compute what index this comes from, and check for path translations
string dbdir = m_rcldb->m_basedir; string dbdir = m_rcldb->m_basedir;
if (!m_rcldb->m_extraDbs.empty()) { if (!m_rcldb->m_extraDbs.empty()) {
@ -364,6 +366,21 @@ bool Db::Native::dbDataToRclDoc(Xapian::docid docid, std::string &data,
return true; return true;
} }
bool Db::Native::hasPages(Xapian::docid docid)
{
string ermsg;
Xapian::PositionIterator pos;
XAPTRY(pos = xrdb.positionlist_begin(docid, page_break_term);
if (pos != xrdb.positionlist_end(docid, page_break_term)) {
return true;
},
xrdb, ermsg);
if (!ermsg.empty()) {
LOGERR(("Db::Native::hasPages: xapian error: %s\n", ermsg.c_str()));
}
return false;
}
// Return the positions list for the page break term // Return the positions list for the page break term
bool Db::Native::getPagePositions(Xapian::docid docid, vector<int>& vpos) bool Db::Native::getPagePositions(Xapian::docid docid, vector<int>& vpos)
{ {

View File

@ -150,6 +150,9 @@ class Db::Native {
* *
*/ */
bool subDocs(const string &udi, vector<Xapian::docid>& docids); bool subDocs(const string &udi, vector<Xapian::docid>& docids);
/** Check if a page position list is defined */
bool hasPages(Xapian::docid id);
}; };
// This is the word position offset at which we index the body text // This is the word position offset at which we index the body text

View File

@ -264,7 +264,7 @@ bool Query::getQueryTerms(vector<string>& terms)
return true; return true;
} }
int Query::makeDocAbstract(Doc &doc, int Query::makeDocAbstract(const Doc &doc,
vector<Snippet>& abstract, vector<Snippet>& abstract,
int maxoccs, int ctxwords) int maxoccs, int ctxwords)
{ {
@ -284,7 +284,7 @@ int Query::makeDocAbstract(Doc &doc,
return ret; return ret;
} }
bool Query::makeDocAbstract(Doc &doc, vector<string>& abstract) bool Query::makeDocAbstract(const Doc &doc, vector<string>& abstract)
{ {
vector<Snippet> vpabs; vector<Snippet> vpabs;
if (!makeDocAbstract(doc, vpabs)) if (!makeDocAbstract(doc, vpabs))
@ -293,7 +293,6 @@ bool Query::makeDocAbstract(Doc &doc, vector<string>& abstract)
it != vpabs.end(); it++) { it != vpabs.end(); it++) {
string chunk; string chunk;
if (it->page > 0) { if (it->page > 0) {
doc.haspages = true;
ostringstream ss; ostringstream ss;
ss << it->page; ss << it->page;
chunk += string(" [p ") + ss.str() + "] "; chunk += string(" [p ") + ss.str() + "] ";
@ -304,7 +303,7 @@ bool Query::makeDocAbstract(Doc &doc, vector<string>& abstract)
return true; return true;
} }
bool Query::makeDocAbstract(Doc &doc, string& abstract) bool Query::makeDocAbstract(const Doc &doc, string& abstract)
{ {
vector<Snippet> vpabs; vector<Snippet> vpabs;
if (!makeDocAbstract(doc, vpabs)) if (!makeDocAbstract(doc, vpabs))
@ -317,9 +316,9 @@ bool Query::makeDocAbstract(Doc &doc, string& abstract)
return m_reason.empty() ? true : false; return m_reason.empty() ? true : false;
} }
int Query::getFirstMatchPage(Doc &doc, string& term) int Query::getFirstMatchPage(const Doc &doc, string& term)
{ {
LOGDEB1(("Db::getFirstMatchPages\n"));; LOGDEB1(("Db::getFirstMatchPage\n"));;
if (!m_nq) { if (!m_nq) {
LOGERR(("Query::getFirstMatchPage: no nq\n")); LOGERR(("Query::getFirstMatchPage: no nq\n"));
return false; return false;

View File

@ -106,14 +106,15 @@ class Query {
/** Build synthetic abstract for document, extracting chunks relevant for /** Build synthetic abstract for document, extracting chunks relevant for
* the input query. This uses index data only (no access to the file) */ * the input query. This uses index data only (no access to the file) */
// Abstract returned as one string // Abstract returned as one string
bool makeDocAbstract(Doc &doc, std::string& abstract); bool makeDocAbstract(const Doc &doc, std::string& abstract);
// Returned as a snippets vector // Returned as a snippets vector
bool makeDocAbstract(Doc &doc, std::vector<std::string>& abstract); bool makeDocAbstract(const Doc &doc, std::vector<std::string>& abstract);
// Returned as a vector of pair<page,snippet> page is 0 if unknown // Returned as a vector of pair<page,snippet> page is 0 if unknown
int makeDocAbstract(Doc &doc, std::vector<Snippet>& abst, int makeDocAbstract(const Doc &doc, std::vector<Snippet>& abst,
int maxoccs= -1, int ctxwords = -1); int maxoccs= -1, int ctxwords = -1);
/** Retrieve page number for first match for term */ /** Retrieve page number for first match for "significant" query term
int getFirstMatchPage(Doc &doc, std::string& term); * @param term returns the chosen term */
int getFirstMatchPage(const Doc &doc, std::string& term);
/** Retrieve a reference to the searchData we are using */ /** Retrieve a reference to the searchData we are using */
RefCntr<SearchData> getSD() RefCntr<SearchData> getSD()