Ticket #450: dbcheck.patch
File dbcheck.patch, 3.7 KB (added by , 15 years ago) |
---|
-
dbcheck.cc
140 140 // We build this up from the documents, and then check it against the 141 141 // equivalent built up from the posting lists. 142 142 map<string, string> posting_reprs; 143 map<Xapian::valueno, string> value_reprs; 143 144 145 Xapian::termcount doclen_lower_bound = Xapian::termcount(-1); 146 Xapian::termcount doclen_upper_bound = 0; 147 144 148 for (Xapian::PostingIterator dociter = db.postlist_begin(string()); 145 149 dociter != db.postlist_end(string()); 146 150 ++dociter) { … … 148 152 TEST_EQUAL(dociter.get_wdf(), 1); 149 153 Xapian::Document doc(db.get_document(did)); 150 154 Xapian::termcount doclen(db.get_doclength(did)); 155 if (doclen < doclen_lower_bound) 156 doclen_lower_bound = doclen; 157 if (doclen > doclen_upper_bound) 158 doclen_upper_bound = doclen; 151 159 totlen += doclen; 152 160 153 161 Xapian::termcount found_termcount = 0; … … 196 204 i->second += "," + posting_repr; 197 205 } 198 206 } 207 208 Xapian::termcount vcount = 0; 209 for (Xapian::ValueIterator v = doc.values_begin(); 210 v != doc.values_end(); 211 ++v, ++vcount) { 212 TEST((*v).size() != 0); 213 string value_repr = "(" + str(did) + "," + *v + ")"; 214 215 // Append the values to the value lists. 216 map<Xapian::valueno, string>::iterator i; 217 i = value_reprs.find(v.get_valueno()); 218 if (i == value_reprs.end()) { 219 value_reprs[v.get_valueno()] = value_repr; 220 } else { 221 i->second += "," + value_repr; 222 } 223 } 224 TEST_EQUAL(vcount, doc.values_count()); 199 225 TEST(t2 == db.termlist_end(did)); 200 226 Xapian::termcount expected_termcount = doc.termlist_count(); 201 227 TEST_EQUAL(expected_termcount, found_termcount); 202 228 TEST_EQUAL(doclen, wdf_sum); 203 229 } 204 230 231 TEST_REL(doclen_lower_bound, >=, db.get_doclength_lower_bound()); 232 TEST_REL(doclen_upper_bound, <=, db.get_doclength_upper_bound()); 233 205 234 Xapian::TermIterator t; 206 235 map<string, string>::const_iterator i; 207 236 for (t = db.allterms_begin(), i = posting_reprs.begin(); … … 213 242 214 243 Xapian::doccount tf_count = 0; 215 244 Xapian::termcount cf_count = 0; 245 Xapian::termcount wdf_upper_bound = 0; 216 246 string posting_repr; 217 247 bool need_comma = false; 218 248 for (Xapian::PostingIterator p = db.postlist_begin(*t); … … 233 263 posting_repr += "(" + str(*p) + "," + 234 264 str(p.get_wdf()) + "/" + str(p.get_doclength()) + 235 265 posrepr + ")"; 266 if (wdf_upper_bound < p.get_wdf()) 267 wdf_upper_bound = p.get_wdf(); 236 268 need_comma = true; 237 269 } 238 270 … … 240 272 TEST_EQUAL(tf_count, t.get_termfreq()); 241 273 TEST_EQUAL(tf_count, db.get_termfreq(*t)); 242 274 TEST_EQUAL(cf_count, db.get_collection_freq(*t)); 275 TEST_REL(wdf_upper_bound, <=, db.get_wdf_upper_bound(*t)); 243 276 } 244 277 TEST(i == posting_reprs.end()); 245 278 279 map<Xapian::valueno, string>::const_iterator j; 280 for (j = value_reprs.begin(); j != value_reprs.end(); ++j) { 281 string value_repr; 282 string value_lower_bound; 283 string value_upper_bound; 284 bool first = true; 285 for (Xapian::ValueIterator v = db.valuestream_begin(j->first); 286 v != db.valuestream_end(j->first); ++v) { 287 if (first) { 288 value_lower_bound = *v; 289 value_upper_bound = *v; 290 first = false; 291 } else { 292 value_repr += ","; 293 if (*v > value_upper_bound) { 294 value_upper_bound = *v; 295 } 296 if (*v < value_lower_bound) { 297 value_lower_bound = *v; 298 } 299 } 300 value_repr += "(" + str(v.get_docid()) + "," + *v + ")"; 301 } 302 TEST_EQUAL(value_repr, j->second); 303 TEST_REL(value_upper_bound, <=, db.get_value_upper_bound(j->first)); 304 TEST_REL(value_lower_bound, >=, db.get_value_lower_bound(j->first)); 305 } 306 246 307 if (expected_doccount == 0) { 247 308 TEST_EQUAL(0, db.get_avlength()); 248 309 } else {