Store the origin dbdir inside the GUI doc history, so we can later fetch documents from external indexes
This commit is contained in:
+51
-8
@@ -1123,9 +1123,26 @@ bool Db::rmQueryDb(const string &dir)
|
||||
// Determining what index a doc result comes from is based on the
|
||||
// modulo of the docid against the db count. Ref:
|
||||
// http://trac.xapian.org/wiki/FAQ/MultiDatabaseDocumentID
|
||||
size_t Db::whatDbIdx(const Doc& doc)
|
||||
bool Db::fromMainIndex(const Doc& doc)
|
||||
{
|
||||
return m_ndb->whatDbIdx(doc.xdocid);
|
||||
return m_ndb->whatDbIdx(doc.xdocid) == 0;
|
||||
}
|
||||
|
||||
std::string Db::whatIndexForResultDoc(const Doc& doc)
|
||||
{
|
||||
size_t idx = m_ndb->whatDbIdx(doc.xdocid);
|
||||
if (idx == (size_t)-1) {
|
||||
LOGERR("whatIndexForResultDoc: whatDbIdx returned -1 for " <<
|
||||
doc.xdocid << endl);
|
||||
return string();
|
||||
}
|
||||
// idx is [0..m_extraDbs.size()] 0 is for the main index, else
|
||||
// idx-1 indexes into m_extraDbs
|
||||
if (idx == 0) {
|
||||
return m_basedir;
|
||||
} else {
|
||||
return m_extraDbs[idx-1];
|
||||
}
|
||||
}
|
||||
|
||||
size_t Db::Native::whatDbIdx(Xapian::docid id)
|
||||
@@ -2352,18 +2369,44 @@ bool Db::dbStats(DbStats& res, bool listfailed)
|
||||
// existence should be tested by looking at doc.pc
|
||||
bool Db::getDoc(const string &udi, const Doc& idxdoc, Doc &doc)
|
||||
{
|
||||
LOGDEB("Db:getDoc: [" << udi << "]\n");
|
||||
if (m_ndb == 0)
|
||||
return false;
|
||||
LOGDEB1("Db:getDoc: [" << udi << "]\n");
|
||||
int idxi = idxdoc.idxi;
|
||||
return getDoc(udi, idxi, doc);
|
||||
}
|
||||
|
||||
bool Db::getDoc(const string &udi, const std::string& dbdir, Doc &doc)
|
||||
{
|
||||
LOGDEB1("Db::getDoc(udi, dbdir): (" << udi << ", " << dbdir << ")\n");
|
||||
int idxi = -1;
|
||||
if (dbdir.empty() || dbdir == m_basedir) {
|
||||
idxi = 0;
|
||||
} else {
|
||||
for (unsigned int i = 0; i < m_extraDbs.size(); i++) {
|
||||
if (dbdir == m_extraDbs[i]) {
|
||||
idxi = int(i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGDEB1("Db::getDoc(udi, dbdir): idxi: " << idxi << endl);
|
||||
if (idxi < 0) {
|
||||
LOGERR("Db::getDoc(udi, dbdir): dbdir not in current extra dbs\n");
|
||||
return false;
|
||||
}
|
||||
return getDoc(udi, idxi, doc);
|
||||
}
|
||||
|
||||
bool Db::getDoc(const string& udi, int idxi, Doc& doc)
|
||||
{
|
||||
// Initialize what we can in any case. If this is history, caller
|
||||
// will make partial display in case of error
|
||||
if (m_ndb == 0)
|
||||
return false;
|
||||
doc.meta[Rcl::Doc::keyrr] = "100%";
|
||||
doc.pc = 100;
|
||||
Xapian::Document xdoc;
|
||||
Xapian::docid docid;
|
||||
int idxi = idxdoc.idxi;
|
||||
if ((docid = m_ndb->getDoc(udi, idxi, xdoc))) {
|
||||
if (idxi >= 0 && (docid = m_ndb->getDoc(udi, idxi, xdoc))) {
|
||||
string data = xdoc.get_data();
|
||||
doc.meta[Rcl::Doc::keyudi] = udi;
|
||||
return m_ndb->dbDataToRclDoc(docid, data, doc);
|
||||
@@ -2373,7 +2416,7 @@ bool Db::getDoc(const string &udi, const Doc& idxdoc, Doc &doc)
|
||||
// other ok docs further) but indicate the error with
|
||||
// pc = -1
|
||||
doc.pc = -1;
|
||||
LOGINFO("Db:getDoc: no such doc in index: [" << udi << "]\n");
|
||||
LOGINFO("Db:getDoc: no such doc in current index: [" << udi << "]\n");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-8
@@ -336,13 +336,18 @@ public:
|
||||
bool addQueryDb(const string &dir);
|
||||
/** Remove extra database. if dir == "", remove all. */
|
||||
bool rmQueryDb(const string &dir);
|
||||
/** Look where the doc result comes from.
|
||||
* @param doc must come from a db query so that "opaque" xdocid is set.
|
||||
* @return: 0 main index, (size_t)-1 don't know,
|
||||
* other: order of database in add_database() sequence.
|
||||
*/
|
||||
size_t whatDbIdx(const Doc& doc);
|
||||
|
||||
/** Check if document comes from the main index (this is used to
|
||||
decide if we can update the index for it */
|
||||
bool fromMainIndex(const Doc& doc);
|
||||
|
||||
/** Retrieve an index designator for the document result. This is used
|
||||
* by the GUI document history feature for remembering where a
|
||||
* doc comes from and allowing later retrieval (if the ext index
|
||||
* is still active...).
|
||||
*/
|
||||
std::string whatIndexForResultDoc(const Doc& doc);
|
||||
|
||||
/** Tell if directory seems to hold xapian db */
|
||||
static bool testDbDir(const string &dir, bool *stripped = 0);
|
||||
|
||||
@@ -391,9 +396,10 @@ public:
|
||||
int getAbsLen() const {
|
||||
return m_synthAbsLen;
|
||||
}
|
||||
/** Get document for given udi
|
||||
|
||||
/** Get document for given udi and db index
|
||||
*
|
||||
* Used by the 'history' feature, and to retrieve ancestor documents.
|
||||
* Used to retrieve ancestor documents.
|
||||
* @param udi The unique document identifier.
|
||||
* @param idxdoc A document from the same database as an opaque way to pass
|
||||
* the database id (e.g.: when looking for parent in a multi-database
|
||||
@@ -403,6 +409,20 @@ public:
|
||||
*/
|
||||
bool getDoc(const string &udi, const Doc& idxdoc, Doc &doc);
|
||||
|
||||
/** Get document for given udi and index directory.
|
||||
*
|
||||
* Used by the 'history' feature. This supposes that the extra db
|
||||
* is still active.
|
||||
* @param udi The unique document identifier.
|
||||
* @param dbdir The index directory, from storage, as returned by
|
||||
* whatIndexForResultDoc() at the time of the query. Can be
|
||||
* empty to mean "main index" (allows the history to avoid
|
||||
* storing the main dbdir value).
|
||||
* @param[out] doc The output Recoll document.
|
||||
* @return True for success.
|
||||
*/
|
||||
bool getDoc(const string &udi, const std::string& dbdir, Doc &doc);
|
||||
|
||||
/** Test if documents has sub-documents.
|
||||
*
|
||||
* This can always be detected for file-level documents, using the
|
||||
@@ -548,6 +568,8 @@ private:
|
||||
bool maybeflush(int64_t moretext);
|
||||
bool docExists(const string& uniterm);
|
||||
|
||||
bool getDoc(const std::string& udi, int idxi, Doc& doc);
|
||||
|
||||
/* Copyconst and assignement private and forbidden */
|
||||
Db(const Db &) {}
|
||||
Db& operator=(const Db &) {return *this;};
|
||||
|
||||
Reference in New Issue
Block a user