00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "api_collapse.h"
00024
00025 #include <xapian.h>
00026
00027 #include "apitest.h"
00028 #include "testutils.h"
00029
00030 using namespace std;
00031
00033 DEFINE_TESTCASE(collapsekey5,backend) {
00034 Xapian::Database db(get_database("apitest_simpledata"));
00035 Xapian::Enquire enquire(db);
00036
00037 enquire.set_query(Xapian::Query("this"));
00038
00039 Xapian::MSet full_mset = enquire.get_mset(0, db.get_doccount());
00040
00041 for (Xapian::valueno slot = 0; slot < 10; ++slot) {
00042 map<string, Xapian::doccount> tally;
00043 for (Xapian::docid did = 1; did <= db.get_doccount(); ++did) {
00044 ++tally[db.get_document(did).get_value(slot)];
00045 }
00046
00047 for (Xapian::doccount cmax = db.get_doccount() + 1; cmax > 0; --cmax) {
00048 tout << "Collapsing on slot " << slot << " max " << cmax << endl;
00049 enquire.set_collapse_key(slot, cmax);
00050 Xapian::MSet mset = enquire.get_mset(0, full_mset.size());
00051
00052
00053 Xapian::doccount expect_size = 0;
00054 map<string, Xapian::doccount>::const_iterator i;
00055 for (i = tally.begin(); i != tally.end(); ++i) {
00056 if (i->first.empty() || i->second <= cmax) {
00057 expect_size += i->second;
00058 } else {
00059 expect_size += cmax;
00060 }
00061 }
00062 TEST_EQUAL(mset.size(), expect_size);
00063
00064
00065
00066 map<string, Xapian::doccount> seen;
00067 for (Xapian::MSetIterator j = mset.begin(); j != mset.end(); ++j) {
00068 const string & key = j.get_collapse_key();
00069 TEST(tally.find(key) != tally.end());
00070 ++seen[key];
00071 }
00072 for (i = tally.begin(); i != tally.end(); ++i) {
00073 if (i->first.empty() || i->second <= cmax) {
00074 TEST_EQUAL(seen[i->first], i->second);
00075 } else {
00076 TEST_EQUAL(seen[i->first], cmax);
00077 }
00078 }
00079 }
00080 }
00081
00082 return true;
00083 }