Ticket #270: value_range_alldocs.patch
File value_range_alldocs.patch, 4.4 KB (added by , 16 years ago) |
---|
-
matcher/valuerangepostlist.cc
25 25 #include "autoptr.h" 26 26 #include "omassert.h" 27 27 #include "document.h" 28 #include "leafpostlist.h" 28 29 #include "utils.h" 29 30 30 31 using namespace std; 31 32 33 ValueRangePostList::~ValueRangePostList() 34 { 35 delete alldocs_pl; 36 } 37 32 38 Xapian::doccount 33 39 ValueRangePostList::get_termfreq_min() const 34 40 { … … 104 110 ValueRangePostList::next(Xapian::weight) 105 111 { 106 112 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(); 125 121 } 126 122 db = NULL; 127 123 return NULL; … … 144 140 valid = true; 145 141 return NULL; 146 142 } 147 AssertParanoid(lastdocid == db->get_lastdocid()); 148 AssertRel(did, <=, lastdocid); 143 AssertRelParanoid(did, <=, db->get_lastdocid()); 149 144 current = did; 150 145 AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true)); 151 146 string v = doc->get_value(valno); -
matcher/valuerangepostlist.h
34 34 35 35 Xapian::docid current; 36 36 37 Xapian::doccount lastdocid;38 39 37 Xapian::doccount db_size; 40 38 39 LeafPostList * alldocs_pl; 40 41 41 /// Disallow copying. 42 42 ValueRangePostList(const ValueRangePostList &); 43 43 … … 49 49 Xapian::valueno valno_, 50 50 const std::string &begin_, const std::string &end_) 51 51 : 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) { } 53 53 54 ~ValueRangePostList(); 55 54 56 Xapian::doccount get_termfreq_min() const; 55 57 56 58 Xapian::doccount get_termfreq_est() const; -
matcher/valuegepostlist.cc
26 26 #include "autoptr.h" 27 27 #include "omassert.h" 28 28 #include "document.h" 29 #include "leafpostlist.h" 29 30 #include "utils.h" 30 31 31 32 using namespace std; … … 34 35 ValueGePostList::next(Xapian::weight) 35 36 { 36 37 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(); 48 46 } 49 47 db = NULL; 50 48 return NULL; … … 67 65 valid = true; 68 66 return NULL; 69 67 } 70 AssertParanoid(lastdocid == db->get_lastdocid()); 71 AssertRel(did, <=, lastdocid); 68 AssertRelParanoid(did, <=, db->get_lastdocid()); 72 69 current = did; 73 70 AutoPtr<Xapian::Document::Internal> doc(db->open_document(current, true)); 74 71 string v = doc->get_value(valno);