fix problems with doc fetch sequence (have to know where to stop)

This commit is contained in:
dockes 2006-02-07 10:26:49 +00:00
parent cf07573b57
commit b20222b150
5 changed files with 44 additions and 20 deletions

View File

@ -254,7 +254,7 @@ void ResListBase::showResultPage()
// Insert results if any in result list window. We have to send // Insert results if any in result list window. We have to send
// the text to the widgets, because we need the paragraph number // the text to the widgets, because we need the paragraph number
// each time we add a result paragraph (its diffult and // each time we add a result paragraph (its diffult and
// error-prone to compute the paragraph numbers in parallel. We // error-prone to compute the paragraph numbers in parallel). We
// would like to disable updates while we're doing this, but // would like to disable updates while we're doing this, but
// couldn't find a way to make it work, the widget seems to become // couldn't find a way to make it work, the widget seems to become
// confused if appended while updates are disabled // confused if appended while updates are disabled
@ -264,8 +264,12 @@ void ResListBase::showResultPage()
doc.erase(); doc.erase();
if (!m_docsource->getDoc(m_winfirst + i, doc, &percent, &sh)) { if (!m_docsource->getDoc(m_winfirst + i, doc, &percent, &sh)) {
// This may very well happen for history if the doc has // Error or end of docs, stop.
// been removed since. So don't treat it as fatal. break;
}
if (percent == -1) {
percent = 0;
// Document not available, maybe other further, will go on.
doc.abstract = string(tr("Unavailable document").utf8()); doc.abstract = string(tr("Unavailable document").utf8());
} }

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.7 2006-01-26 12:30:14 dockes Exp $ (C) 2005 J.F.Dockes"; static char rcsid[] = "@(#$Id: docseq.cpp,v 1.8 2006-02-07 10:26:49 dockes Exp $ (C) 2005 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -38,9 +38,9 @@ int DocSequenceDb::getResCnt()
return m_rescnt; return m_rescnt;
} }
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent, bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
string *sh) { string *sh)
{
// Retrieve history list // Retrieve history list
if (!m_hist) if (!m_hist)
return false; return false;
@ -72,7 +72,7 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
} else } else
sh->erase(); sh->erase();
} }
return m_db->getDoc(m_it->fn, m_it->ipath, doc); return m_db->getDoc(m_it->fn, m_it->ipath, doc, percent);
} }
int DocSequenceHistory::getResCnt() int DocSequenceHistory::getResCnt()

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _DOCSEQ_H_INCLUDED_ #ifndef _DOCSEQ_H_INCLUDED_
#define _DOCSEQ_H_INCLUDED_ #define _DOCSEQ_H_INCLUDED_
/* @(#$Id: docseq.h,v 1.5 2006-01-30 11:15:28 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: docseq.h,v 1.6 2006-02-07 10:26:49 dockes Exp $ (C) 2004 J.F.Dockes */
#include "rcldb.h" #include "rcldb.h"
#include "history.h" #include "history.h"
@ -31,6 +31,19 @@ class DocSequence {
public: public:
DocSequence(const std::string &t) : m_title(t) {} DocSequence(const std::string &t) : m_title(t) {}
virtual ~DocSequence() {} virtual ~DocSequence() {}
/** Get document at given rank
*
* @param num document rank in sequence
* @param doc return data
* @param percent this will be updated with the percentage of relevance, if
* available, depending on the type of sequence. Return -1 in there
* to indicate that the specified document data is
* unavailable but that there may be available data further
* in the sequence
* @param sh subheader to display before this result (ie: date change
* inside history)
* @return true if ok, false for error or end of data
*/
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0) virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0)
= 0; = 0;
virtual int getResCnt() = 0; virtual int getResCnt() = 0;

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.56 2006-02-02 08:58:11 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.57 2006-02-07 10:26:49 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -1305,7 +1305,7 @@ bool Rcl::Db::getDoc(int exti, Doc &doc, int *percent)
// Retrieve document defined by file name and internal path. Very inefficient, // Retrieve document defined by file name and internal path. Very inefficient,
// used only for history display. We'd need to enter path+ipath terms in the // used only for history display. We'd need to enter path+ipath terms in the
// db if we wanted to make this more efficient. // db if we wanted to make this more efficient.
bool Rcl::Db::getDoc(const string &fn, const string &ipath, Doc &doc) bool Rcl::Db::getDoc(const string &fn, const string &ipath, Doc &doc, int *pc)
{ {
LOGDEB(("Rcl::Db:getDoc: [%s] (%d) [%s]\n", fn.c_str(), fn.length(), LOGDEB(("Rcl::Db:getDoc: [%s] (%d) [%s]\n", fn.c_str(), fn.length(),
ipath.c_str())); ipath.c_str()));
@ -1313,18 +1313,29 @@ bool Rcl::Db::getDoc(const string &fn, const string &ipath, Doc &doc)
return false; return false;
Native *ndb = (Native *)pdata; Native *ndb = (Native *)pdata;
// Initialize what we can in any case. If this is history, caller
// will make partial display in case of error
doc.ipath = ipath;
doc.url = string("file://") + fn;
if (*pc)
*pc = 100;
string hash; string hash;
pathHash(fn, hash, PATHHASHLEN); pathHash(fn, hash, PATHHASHLEN);
string pathterm = "P" + hash; string pathterm = "P" + hash;
// Look for all documents with this path, searching for the one // Look for all documents with this path, searching for the one
// with the appropriate ipath. This is very inefficient. // with the appropriate ipath. This is very inefficient.
const char *ermsg = ""; const char *ermsg = "";
try { try {
if (!ndb->db.term_exists(pathterm)) { if (!ndb->db.term_exists(pathterm)) {
char len[20]; // Document found in history no longer in the database.
sprintf(len, "%d", int(pathterm.length())); // We return true (because their might be other ok docs further)
throw string("path inexistant: [") + pathterm +"] length " + len; // but indicate the error with pc = -1
if (*pc)
*pc = -1;
LOGINFO(("Rcl::Db:getDoc: path inexistant: [%s] length %d\n",
pathterm.c_str(), pathterm.length()));
return true;
} }
for (Xapian::PostingIterator docid = for (Xapian::PostingIterator docid =
ndb->db.postlist_begin(pathterm); ndb->db.postlist_begin(pathterm);
@ -1348,10 +1359,6 @@ bool Rcl::Db::getDoc(const string &fn, const string &ipath, Doc &doc)
} }
if (*ermsg) { if (*ermsg) {
LOGERR(("Rcl::Db::getDoc: %s\n", ermsg)); LOGERR(("Rcl::Db::getDoc: %s\n", ermsg));
// Initialize what we can anyway. If this is history, caller
// will make partial display
doc.ipath = ipath;
doc.url = string("file://") + fn;
} }
return false; return false;
} }

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _DB_H_INCLUDED_ #ifndef _DB_H_INCLUDED_
#define _DB_H_INCLUDED_ #define _DB_H_INCLUDED_
/* @(#$Id: rcldb.h,v 1.24 2006-01-30 11:15:27 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: rcldb.h,v 1.25 2006-02-07 10:26:49 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string> #include <string>
#include <list> #include <list>
@ -154,7 +154,7 @@ class Db {
bool getDoc(int i, Doc &doc, int *percent = 0); bool getDoc(int i, Doc &doc, int *percent = 0);
/** Get document for given filename and ipath */ /** Get document for given filename and ipath */
bool getDoc(const string &fn, const string &ipath, Doc &doc); bool getDoc(const string &fn, const string &ipath, Doc &doc, int *percent);
/** Get results count for current query */ /** Get results count for current query */
int getResCnt(); int getResCnt();