Ticket #270: value_range_alldocs.patch

File value_range_alldocs.patch, 4.4 KB (added by Richard Boulton, 16 years ago)

Patch to implement iteration using an alldocs postlist (originally from olly, updated to apply to HEAD)

  • matcher/valuerangepostlist.cc

     
    2525#include "autoptr.h"
    2626#include "omassert.h"
    2727#include "document.h"
     28#include "leafpostlist.h"
    2829#include "utils.h"
    2930
    3031using namespace std;
    3132
     33ValueRangePostList::~ValueRangePostList()
     34{
     35    delete alldocs_pl;
     36}
     37
    3238Xapian::doccount
    3339ValueRangePostList::get_termfreq_min() const
    3440{
     
    104110ValueRangePostList::next(Xapian::weight)
    105111{
    106112    Assert(db);
    107     AssertParanoid(lastdocid == db->get_lastdocid());
    108     while (current < lastdocid && ++current != 0) {
    109         // Wrap both calls to open_document in a try-catch block; in theory,
    110         // only the call with lazy=false should raise the
    111         // Xapian::DocNotFoundError, but the inmemory database ignores the lazy
    112         // flag, so we need to catch the exception from the lazy=true call too.
    113         try {
    114             AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
    115             string v = doc->get_value(valno);
    116             if (v >= begin && v <= end) {
    117                 if (v.empty()) {
    118                     delete db->open_document(current, false);
    119                 }
    120                 return NULL;
    121             }
    122         } catch (const Xapian::DocNotFoundError &) {
    123             continue;
    124         }
     113    if (!alldocs_pl) alldocs_pl = db->open_post_list(string());
     114    alldocs_pl->skip_to(current + 1);
     115    while (!alldocs_pl->at_end()) {
     116        current = alldocs_pl->get_docid();
     117        AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
     118        string v = doc->get_value(valno);
     119        if (v >= begin && v <= end) return NULL;
     120        alldocs_pl->next();
    125121    }
    126122    db = NULL;
    127123    return NULL;
     
    144140        valid = true;
    145141        return NULL;
    146142    }
    147     AssertParanoid(lastdocid == db->get_lastdocid());
    148     AssertRel(did, <=, lastdocid);
     143    AssertRelParanoid(did, <=, db->get_lastdocid());
    149144    current = did;
    150145    AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
    151146    string v = doc->get_value(valno);
  • matcher/valuerangepostlist.h

     
    3434
    3535    Xapian::docid current;
    3636
    37     Xapian::doccount lastdocid;
    38 
    3937    Xapian::doccount db_size;
    4038
     39    LeafPostList * alldocs_pl;
     40
    4141    /// Disallow copying.
    4242    ValueRangePostList(const ValueRangePostList &);
    4343
     
    4949                       Xapian::valueno valno_,
    5050                       const std::string &begin_, const std::string &end_)
    5151        : db(db_), valno(valno_), begin(begin_), end(end_), current(0),
    52           lastdocid(db->get_lastdocid()), db_size(db->get_doccount()) { }
     52          db_size(db->get_doccount()), alldocs_pl(0) { }
    5353
     54    ~ValueRangePostList();
     55
    5456    Xapian::doccount get_termfreq_min() const;
    5557
    5658    Xapian::doccount get_termfreq_est() const;
  • matcher/valuegepostlist.cc

     
    2626#include "autoptr.h"
    2727#include "omassert.h"
    2828#include "document.h"
     29#include "leafpostlist.h"
    2930#include "utils.h"
    3031
    3132using namespace std;
     
    3435ValueGePostList::next(Xapian::weight)
    3536{
    3637    Assert(db);
    37     AssertParanoid(lastdocid == db->get_lastdocid());
    38     while (current < lastdocid) {
    39         try {
    40             if (++current == 0) break;
    41             AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
    42             string v = doc->get_value(valno);
    43             if (v >= begin) return NULL;
    44         } catch (const Xapian::DocNotFoundError &) {
    45             // That document doesn't exist.
    46             // FIXME: this could throw and catch a lot of exceptions!
    47         }
     38    if (!alldocs_pl) alldocs_pl = db->open_post_list(string());
     39    alldocs_pl->skip_to(current + 1);
     40    while (!alldocs_pl->at_end()) {
     41        current = alldocs_pl->get_docid();
     42        AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
     43        string v = doc->get_value(valno);
     44        if (v >= begin) return NULL;
     45        alldocs_pl->next();
    4846    }
    4947    db = NULL;
    5048    return NULL;
     
    6765        valid = true;
    6866        return NULL;
    6967    }
    70     AssertParanoid(lastdocid == db->get_lastdocid());
    71     AssertRel(did, <=, lastdocid);
     68    AssertRelParanoid(did, <=, db->get_lastdocid());
    7269    current = did;
    7370    AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true));
    7471    string v = doc->get_value(valno);