Ticket #295: multipostsource.patch
File multipostsource.patch, 11.7 KB (added by , 16 years ago) |
---|
-
xapian-core/matcher/externalpostlist.cc
29 29 30 30 using namespace std; 31 31 32 ExternalPostList::ExternalPostList(Xapian::PostingSource *source_, 32 ExternalPostList::ExternalPostList(const Xapian::Database & db, 33 Xapian::PostingSource *source_, 33 34 double factor_) 34 : source(source_), current(0), factor(factor_)35 : source(source_), source_is_owned(false), current(0), factor(factor_) 35 36 { 36 37 Assert(source); 37 source->reset(); 38 Xapian::PostingSource * newsource = source->clone(); 39 if (newsource != NULL) { 40 source = newsource; 41 source_is_owned = true; 42 } 43 source->reset(db); 38 44 } 39 45 46 ExternalPostList::~ExternalPostList() 47 { 48 if (source_is_owned) { 49 delete source; 50 } 51 } 52 40 53 Xapian::doccount 41 54 ExternalPostList::get_termfreq_min() const 42 55 { -
xapian-core/matcher/queryoptimiser.cc
64 64 65 65 case Xapian::Query::Internal::OP_EXTERNAL_SOURCE: 66 66 Assert(query->external_source); 67 RETURN(new ExternalPostList(query->external_source, factor)); 67 RETURN(new ExternalPostList( 68 Xapian::Database(const_cast<Xapian::Database::Internal *>(&db)), 69 query->external_source, factor)); 68 70 69 71 case Xapian::Query::OP_AND: 70 72 case Xapian::Query::OP_FILTER: -
xapian-core/matcher/externalpostlist.h
29 29 30 30 class ExternalPostList : public PostList { 31 31 Xapian::PostingSource * source; 32 bool source_is_owned; 32 33 33 34 Xapian::docid current; 34 35 … … 43 44 PostList * update_after_advance(); 44 45 45 46 public: 46 ExternalPostList(Xapian::PostingSource *source_, double factor_); 47 ExternalPostList(const Xapian::Database & db, 48 Xapian::PostingSource *source_, 49 double factor_); 50 ~ExternalPostList(); 47 51 48 52 Xapian::doccount get_termfreq_min() const; 49 53 -
xapian-core/tests/api_db.cc
1887 1887 : num_docs(db.get_doccount()), last_docid(db.get_lastdocid()), did(0) 1888 1888 { } 1889 1889 1890 void reset( ) { did = 0; }1890 void reset(const Xapian::Database &) { did = 0; } 1891 1891 1892 1892 // These bounds could be better, but that's not important here. 1893 1893 Xapian::doccount get_termfreq_min() const { return 0; } … … 1981 1981 : num_docs(db.get_doccount()), last_docid(db.get_lastdocid()), did(0) 1982 1982 { } 1983 1983 1984 void reset( ) { did = 0; }1984 void reset(const Xapian::Database &) { did = 0; } 1985 1985 1986 1986 Xapian::weight get_weight() const { 1987 1987 return (did % 2) ? 1000 : 0.001; … … 2078 2078 : num_docs(db.get_doccount()), last_docid(db.get_lastdocid()), did(0) 2079 2079 { } 2080 2080 2081 void reset( ) { did = 0; }2081 void reset(const Xapian::Database &) { did = 0; } 2082 2082 2083 2083 Xapian::weight get_weight() const { 2084 2084 FAIL_TEST("MyDontAskWeightPostingSource::get_weight() called"); … … 2152 2152 2153 2153 // Check that valueweightsource works correctly. 2154 2154 DEFINE_TESTCASE(valueweightsource1, backend && !remote) { 2155 // FIXME: PostingSource doesn't currently work well with multi databases2156 // but we should try to resolve that issue.2157 SKIP_TEST_FOR_BACKEND("multi");2158 2155 Xapian::Database db(get_database("apitest_phrase")); 2159 2156 Xapian::Enquire enq(db); 2160 Xapian::ValueWeightPostingSource src( db,11);2157 Xapian::ValueWeightPostingSource src(11); 2161 2158 2162 2159 // Should be in descending order of length 2163 2160 tout << "RAW" << endl; … … 2189 2186 // Check that valueweightsource gives the correct bounds for those databases 2190 2187 // which support value statistics. 2191 2188 DEFINE_TESTCASE(valueweightsource2, backend && valuestats) { 2192 // FIXME: PostingSource doesn't currently work well with multi databases2193 // but we should try to resolve that issue.2194 SKIP_TEST_FOR_BACKEND("multi");2195 2189 Xapian::Database db(get_database("apitest_phrase")); 2196 Xapian::ValueWeightPostingSource src(db, 11); 2190 Xapian::ValueWeightPostingSource src(11); 2191 src.reset(db); 2197 2192 TEST_EQUAL(src.get_termfreq_min(), 17); 2198 2193 TEST_EQUAL(src.get_termfreq_est(), 17); 2199 2194 TEST_EQUAL(src.get_termfreq_max(), 17); … … 2204 2199 2205 2200 // Check that valueweightsource skip_to() can stay in the same position. 2206 2201 DEFINE_TESTCASE(valueweightsource3, backend && valuestats) { 2207 // FIXME: PostingSource doesn't currently work well with multi databases2208 // but we should try to resolve that issue.2209 SKIP_TEST_FOR_BACKEND("multi");2210 2202 Xapian::Database db(get_database("apitest_phrase")); 2211 Xapian::ValueWeightPostingSource src(db, 11); 2203 Xapian::ValueWeightPostingSource src(11); 2204 src.reset(db); 2212 2205 TEST(!src.at_end()); 2213 2206 src.skip_to(8, 0.0); 2214 2207 TEST(!src.at_end()); -
xapian-core/tests/api_percentages.cc
55 55 if (wt > maxwt) maxwt = wt; 56 56 } 57 57 58 void reset( ) { started = false; }58 void reset(const Xapian::Database &) { started = false; } 59 59 60 60 Xapian::weight get_weight() const { 61 61 return i->second; -
xapian-core/include/xapian/postingsource.h
137 137 /// Return the current docid. 138 138 virtual Xapian::docid get_docid() const = 0; 139 139 140 /** Clone the posting source. 141 * 142 * FIXME - more documentation needed. 143 * 144 * This may return NULL to indicate that cloning is not possible. In this 145 * case, the PostingSource will work only if a single database is being 146 * searched. The default implementation returns NULL. 147 */ 148 virtual PostingSource * clone() const; 149 140 150 /** Reset this PostingSource to its freshly constructed state. 141 151 * 142 152 * This is called automatically by the matcher prior to each query being 143 153 * processed. 154 * 155 * FIXME - document the db parameter. 144 156 */ 145 virtual void reset( ) = 0;157 virtual void reset(const Database & db) = 0; 146 158 147 159 /** Return a string describing this object. 148 160 * … … 196 208 /// An upper bound on the value returned. 197 209 double max_value; 198 210 211 /// Upper bound on the value returned specified in constructor. 212 double specified_max_value; 213 199 214 public: 200 215 /** Construct a ValueWeightPostingSource. 201 216 * 202 217 * @param db_ The database to read values from. 203 218 * @param valno_ The value slot to read values from. 204 219 */ 205 ValueWeightPostingSource(Xapian:: Database db_, Xapian::valueno valno_);220 ValueWeightPostingSource(Xapian::valueno valno_); 206 221 207 222 /** Construct a ValueWeightPostingSource. 208 223 * … … 214 229 * constructor need only be used if more accurate information is 215 230 * available. 216 231 */ 217 ValueWeightPostingSource(Xapian::Database db_, Xapian::valueno valno_, 218 double max_weight_); 232 ValueWeightPostingSource(Xapian::valueno valno_, double max_weight_); 219 233 220 234 Xapian::doccount get_termfreq_min() const; 221 235 Xapian::doccount get_termfreq_est() const; … … 232 246 233 247 Xapian::docid get_docid() const; 234 248 235 void reset(); 249 ValueWeightPostingSource * clone() const; 250 void reset(const Database & db_); 236 251 237 252 std::string get_description() const; 238 253 }; -
xapian-core/api/postingsource.cc
67 67 return true; 68 68 } 69 69 70 PostingSource * 71 PostingSource::clone() const 72 { 73 return NULL; 74 } 75 76 70 77 std::string 71 78 PostingSource::get_description() const 72 79 { … … 74 81 } 75 82 76 83 77 ValueWeightPostingSource::ValueWeightPostingSource(Xapian::Database db_, 78 Xapian::valueno valno_) 79 : db(db_), 80 valno(valno_), 81 current_docid(0), 82 last_docid(db.get_lastdocid()), 83 current_value(0.0) 84 ValueWeightPostingSource::ValueWeightPostingSource(Xapian::valueno valno_) 85 : valno(valno_), 86 specified_max_value(DBL_MAX) 84 87 { 85 try {86 termfreq_max = db.get_value_freq(valno);87 termfreq_est = termfreq_max;88 termfreq_min = termfreq_max;89 max_value = sortable_unserialise(db.get_value_upper_bound(valno));90 } catch (const Xapian::UnimplementedError &) {91 termfreq_max = db.get_doccount();92 termfreq_est = termfreq_max / 2;93 termfreq_min = 0;94 max_value = DBL_MAX;95 }96 88 } 97 89 98 ValueWeightPostingSource::ValueWeightPostingSource(Xapian::Database db_, 99 Xapian::valueno valno_, 90 ValueWeightPostingSource::ValueWeightPostingSource(Xapian::valueno valno_, 100 91 double max_weight_) 101 : db(db_), 102 valno(valno_), 103 current_docid(0), 104 last_docid(db.get_lastdocid()), 105 current_value(0.0), 106 max_value(max_weight_) 92 : valno(valno_), 93 specified_max_value(max_weight_) 107 94 { 108 try {109 termfreq_max = db.get_value_freq(valno);110 termfreq_est = termfreq_max;111 termfreq_min = termfreq_max;112 max_value = std::min(max_value,113 sortable_unserialise(db.get_value_upper_bound(valno)));114 } catch (const Xapian::UnimplementedError &) {115 termfreq_max = db.get_doccount();116 termfreq_est = termfreq_max / 2;117 termfreq_min = 0;118 }119 95 } 120 96 121 97 Xapian::doccount … … 232 208 return current_docid; 233 209 } 234 210 211 ValueWeightPostingSource * 212 ValueWeightPostingSource::clone() const 213 { 214 return new ValueWeightPostingSource(valno, specified_max_value); 215 } 216 235 217 void 236 ValueWeightPostingSource::reset( )218 ValueWeightPostingSource::reset(const Database & db_) 237 219 { 220 db = db_; 238 221 current_docid = 0; 222 current_value = 0.0; 223 last_docid = db.get_lastdocid(); 224 try { 225 termfreq_max = db.get_value_freq(valno); 226 termfreq_est = termfreq_max; 227 termfreq_min = termfreq_max; 228 max_value = std::min(specified_max_value, 229 sortable_unserialise(db.get_value_upper_bound(valno))); 230 } catch (const Xapian::UnimplementedError &) { 231 termfreq_max = db.get_doccount(); 232 termfreq_est = termfreq_max / 2; 233 termfreq_min = 0; 234 max_value = specified_max_value; 235 } 239 236 } 240 237 241 238 std::string -
xapian-bindings/python/pythontest2.py
912 912 xapian.PostingSource.__init__(self) 913 913 self.max = max 914 914 915 def reset(self ):915 def reset(self, db): 916 916 self.current = -1 917 917 918 918 def get_termfreq_min(self): return 0 … … 953 953 doc.add_value(1, xapian.sortable_serialise(vals[id])) 954 954 db.add_document(doc) 955 955 956 source = xapian.ValueWeightPostingSource( db,1)956 source = xapian.ValueWeightPostingSource(1) 957 957 query = xapian.Query(source) 958 958 # del source # Check that query keeps a reference to it. 959 959 -
xapian-bindings/xapian.i
194 194 195 195 #ifdef XAPIAN_SWIG_DIRECTORS 196 196 %feature("director") Xapian::PostingSource; 197 %ignore Xapian::PostingSource::clone; 197 198 %include <xapian/postingsource.h> 198 199 #else 199 200 %ignore Xapian::Query(Xapian::PostingSource *);