Ticket #450: dbcheck.patch

File dbcheck.patch, 3.7 KB (added by Richard Boulton, 14 years ago)

Patch to dbcheck to check integrity of bounds

  • dbcheck.cc

     
    140140    // We build this up from the documents, and then check it against the
    141141    // equivalent built up from the posting lists.
    142142    map<string, string> posting_reprs;
     143    map<Xapian::valueno, string> value_reprs;
    143144
     145    Xapian::termcount doclen_lower_bound = Xapian::termcount(-1);
     146    Xapian::termcount doclen_upper_bound = 0;
     147
    144148    for (Xapian::PostingIterator dociter = db.postlist_begin(string());
    145149         dociter != db.postlist_end(string());
    146150         ++dociter) {
     
    148152        TEST_EQUAL(dociter.get_wdf(), 1);
    149153        Xapian::Document doc(db.get_document(did));
    150154        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;
    151159        totlen += doclen;
    152160
    153161        Xapian::termcount found_termcount = 0;
     
    196204                i->second += "," + posting_repr;
    197205            }
    198206        }
     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());
    199225        TEST(t2 == db.termlist_end(did));
    200226        Xapian::termcount expected_termcount = doc.termlist_count();
    201227        TEST_EQUAL(expected_termcount, found_termcount);
    202228        TEST_EQUAL(doclen, wdf_sum);
    203229    }
    204230
     231    TEST_REL(doclen_lower_bound, >=, db.get_doclength_lower_bound());
     232    TEST_REL(doclen_upper_bound, <=, db.get_doclength_upper_bound());
     233
    205234    Xapian::TermIterator t;
    206235    map<string, string>::const_iterator i;
    207236    for (t = db.allterms_begin(), i = posting_reprs.begin();
     
    213242
    214243        Xapian::doccount tf_count = 0;
    215244        Xapian::termcount cf_count = 0;
     245        Xapian::termcount wdf_upper_bound = 0;
    216246        string posting_repr;
    217247        bool need_comma = false;
    218248        for (Xapian::PostingIterator p = db.postlist_begin(*t);
     
    233263            posting_repr += "(" + str(*p) + "," +
    234264                    str(p.get_wdf()) + "/" + str(p.get_doclength()) +
    235265                    posrepr + ")";
     266            if (wdf_upper_bound < p.get_wdf())
     267                wdf_upper_bound = p.get_wdf();
    236268            need_comma = true;
    237269        }
    238270
     
    240272        TEST_EQUAL(tf_count, t.get_termfreq());
    241273        TEST_EQUAL(tf_count, db.get_termfreq(*t));
    242274        TEST_EQUAL(cf_count, db.get_collection_freq(*t));
     275        TEST_REL(wdf_upper_bound, <=, db.get_wdf_upper_bound(*t));
    243276    }
    244277    TEST(i == posting_reprs.end());
    245278
     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
    246307    if (expected_doccount == 0) {
    247308        TEST_EQUAL(0, db.get_avlength());
    248309    } else {