Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DEFINE_TESTCASE(set_item_weight, backend) {
- // open the database (in this case a simple text file
- // we prepared earlier)
- Xapian::Database mydb(get_database("apitest_onedoc"));
- Xapian::Enquire enquire(mydb);
- // make a simple query, with one word in it - "word".
- enquire.set_query(Xapian::Query("word"));
- // retrieve the top ten results (we only expect one)
- Xapian::MSet mymset = enquire.get_mset(0, 10);
- vector<double> weights;
- weights.push_back(-1);
- mymset.replace_weights(weights.begin(), weights.end());
- Xapian::MSetIterator i = mymset.begin();
- TEST_EQUAL_DOUBLE_(i.get_weight(), double(-1));
- TEST_EQUAL_DOUBLE_(mymset.get_max_attained(), double(-1));
- return true;
- }
- DEFINE_TESTCASE(set_wrong_item_weights, backend) {
- // open the database (in this case a simple text file
- // we prepared earlier)
- Xapian::Database mydb(get_database("apitest_onedoc"));
- Xapian::Enquire enquire(mydb);
- // make a simple query, with one word in it - "word".
- enquire.set_query(Xapian::Query("word"));
- // retrieve the top ten results (we only expect one)
- Xapian::MSet mymset = enquire.get_mset(0, 10);
- vector<double> weights;
- weights.push_back(-1);
- weights.push_back(-2);
- mymset.replace_weights(weights.begin(), weights.end());
- return true;
- }
- DEFINE_TESTCASE(sort_by_relevance, backend) {
- // open the database (in this case a simple text file
- // we prepared earlier)
- Xapian::Database db = get_database("apitest_simpledata");
- Xapian::Enquire enquire(db);
- enquire.set_query(Xapian::Query("word"));
- // retrieve the top results
- Xapian::MSet mymset = enquire.get_mset(0, 10);
- // We've done the query, now check that the result is what
- // we expect (documents 2 and 4)
- // Check the weights
- vector<Xapian::docid> docids;
- Xapian::MSetIterator i = mymset.begin();
- docids.push_back(*i);
- i++;
- docids.push_back(*i);
- vector<double> weights;
- weights.push_back(-2);
- weights.push_back(-1);
- mymset.replace_weights(weights.begin(),weights.end());
- mymset.sort_by_relevance();
- int j = -1, k = 1;
- bool answer = true;
- for (Xapian::MSetIterator m = mymset.begin(); m != mymset.end(); ++m, --j, --k) {
- TEST_EQUAL(m.get_weight(), j);
- TEST_EQUAL(docids[k], *m);
- }
- TEST_EQUAL(mymset.get_max_possible(),double(-1));
- return true;
- }
Add Comment
Please, Sign In to add comment