From b20222b15021c048cd29b09f0f27f111e1810351 Mon Sep 17 00:00:00 2001 From: dockes Date: Tue, 7 Feb 2006 10:26:49 +0000 Subject: [PATCH] fix problems with doc fetch sequence (have to know where to stop) --- src/qtgui/reslistb.ui.h | 10 +++++++--- src/query/docseq.cpp | 8 ++++---- src/query/docseq.h | 15 ++++++++++++++- src/rcldb/rcldb.cpp | 27 +++++++++++++++++---------- src/rcldb/rcldb.h | 4 ++-- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/qtgui/reslistb.ui.h b/src/qtgui/reslistb.ui.h index d171357c..8057d3b1 100644 --- a/src/qtgui/reslistb.ui.h +++ b/src/qtgui/reslistb.ui.h @@ -254,7 +254,7 @@ void ResListBase::showResultPage() // Insert results if any in result list window. We have to send // the text to the widgets, because we need the paragraph number // 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 // couldn't find a way to make it work, the widget seems to become // confused if appended while updates are disabled @@ -264,8 +264,12 @@ void ResListBase::showResultPage() doc.erase(); if (!m_docsource->getDoc(m_winfirst + i, doc, &percent, &sh)) { - // This may very well happen for history if the doc has - // been removed since. So don't treat it as fatal. + // Error or end of docs, stop. + break; + } + if (percent == -1) { + percent = 0; + // Document not available, maybe other further, will go on. doc.abstract = string(tr("Unavailable document").utf8()); } diff --git a/src/query/docseq.cpp b/src/query/docseq.cpp index 7f48fb95..628673b4 100644 --- a/src/query/docseq.cpp +++ b/src/query/docseq.cpp @@ -1,5 +1,5 @@ #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 /* * This program is free software; you can redistribute it and/or modify @@ -38,9 +38,9 @@ int DocSequenceDb::getResCnt() return m_rescnt; } - bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent, - string *sh) { + string *sh) +{ // Retrieve history list if (!m_hist) return false; @@ -72,7 +72,7 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent, } else 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() diff --git a/src/query/docseq.h b/src/query/docseq.h index 5c82ce3b..babaf6f5 100644 --- a/src/query/docseq.h +++ b/src/query/docseq.h @@ -16,7 +16,7 @@ */ #ifndef _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 "history.h" @@ -31,6 +31,19 @@ class DocSequence { public: DocSequence(const std::string &t) : m_title(t) {} 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) = 0; virtual int getResCnt() = 0; diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index c66bf0d0..815b2082 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -1,5 +1,5 @@ #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 /* * 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, // used only for history display. We'd need to enter path+ipath terms in the // 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(), ipath.c_str())); @@ -1313,18 +1313,29 @@ bool Rcl::Db::getDoc(const string &fn, const string &ipath, Doc &doc) return false; 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; pathHash(fn, hash, PATHHASHLEN); string pathterm = "P" + hash; - // Look for all documents with this path, searching for the one // with the appropriate ipath. This is very inefficient. const char *ermsg = ""; try { if (!ndb->db.term_exists(pathterm)) { - char len[20]; - sprintf(len, "%d", int(pathterm.length())); - throw string("path inexistant: [") + pathterm +"] length " + len; + // Document found in history no longer in the database. + // We return true (because their might be other ok docs further) + // 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 = ndb->db.postlist_begin(pathterm); @@ -1348,10 +1359,6 @@ bool Rcl::Db::getDoc(const string &fn, const string &ipath, Doc &doc) } if (*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; } diff --git a/src/rcldb/rcldb.h b/src/rcldb/rcldb.h index 8cc3712a..61e78852 100644 --- a/src/rcldb/rcldb.h +++ b/src/rcldb/rcldb.h @@ -16,7 +16,7 @@ */ #ifndef _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 #include @@ -154,7 +154,7 @@ class Db { bool getDoc(int i, Doc &doc, int *percent = 0); /** 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 */ int getResCnt();