38 static const int keys[] = { 3, 1 };
45 for (
auto m = mset.
begin(); m != mset.
end(); ++m) {
46 const string& data = m.get_document().get_data();
49 exp += string(2,
'\0');
64 for (
auto m = mset.
begin(); m != mset.
end(); ++m) {
65 const string& data = m.get_document().get_data();
68 exp += string(2,
'\0');
69 exp += char(0xff - data[1]);
70 exp += string(2,
'\xff');
85 for (
auto m = mset.
begin(); m != mset.
end(); ++m) {
86 const string& data = m.get_document().get_data();
88 exp += string(2,
'\0');
90 exp += string(2,
'\0');
91 exp += char(0xff - data[1]);
92 exp += string(2,
'\xff');
106 for (
auto m = mset.
begin(); m != mset.
end(); ++m) {
107 const string& data = m.get_document().get_data();
109 if (data.size() > 10) exp += data[10];
110 exp += string(2,
'\0');
111 exp += char(0xff - data[1]);
112 exp += string(2,
'\xff');
143 enquire.set_sort_by_key(&sorter,
true);
151 enquire.set_sort_by_key(&sorter,
true);
160 enquire.set_sort_by_key(&sorter,
true);
169 enquire.set_sort_by_key(&sorter,
true);
178 enquire.set_sort_by_key(&sorter,
true);
187 enquire.set_sort_by_key(&sorter,
true);
255 FAIL_TEST(
"NeverUseMeKeyMaker was called");
289 FAIL_TEST(
"NeverUseMeKeyMaker::operator() didn't throw TestFail");
310 static const int keys[] = { 0, 1, 2, 3 };
314 TEST(sorter(doc).empty());
317 TEST_EQUAL(sorter(doc),
string(
"\0\0foo", 5));
319 TEST_EQUAL(sorter(doc),
string(
"\0\0f\0\xffo", 6));
321 TEST_EQUAL(sorter(doc),
string(
"\0\0f\0\xffo\0\0\0\0xyz", 13));
325 TEST_EQUAL(sorter(doc),
string(
"\0\0f\0\xffo\0\0\0\0xyz\0\0\xff\xff", 17));
329 TEST_EQUAL(sorter(doc),
string(
"\0\0f\0\xffo\0\0\0\0xyz\0\0\xff\xff", 17));
333 TEST_EQUAL(sorter(doc),
string(
"\0\0f\0\xffo\0\0\0\0xyz\0\0\xff\xff\0\0hi",
338 TEST_EQUAL(sorter(doc),
string(
"\0\0f\0\xffo\0\0\0\0xyz\0\0\xff\xff\0\0hi"
339 "\0\0\x97\x96\xff\xff", 27));
360 const double new_weight = 0.125;
361 static const double weights[] = {new_weight};
375 static const double weights[] = {1.0, 2.0};
385 static const Xapian::docid docids[] = {*mymset[0], *mymset[1]};
387 double weights[] = {max_weight * 0.5, max_weight + 1.0};
DEFINE_TESTCASE(sortfunctor1, backend)
Xapian::Database get_database(const string &dbname)
test functionality of the Xapian API
Class which is thrown when a test case fails.
An indexed database of documents.
std::string get_value_upper_bound(Xapian::valueno slot) const
Get an upper bound on the values stored in the given value slot.
Class representing a document.
void add_term(std::string_view term, Xapian::termcount wdf_inc=1)
Add a term to this document.
void add_value(Xapian::valueno slot, std::string_view value)
Add a value to a slot in this document.
void set_sort_by_key(KeyMaker *sorter, bool reverse) XAPIAN_NONNULL()
Set the sorting to be by key generated from values only.
MSet get_mset(doccount first, doccount maxitems, doccount checkatleast=0, const RSet *rset=NULL, const MatchDecider *mdecider=NULL) const
Run the query.
void set_sort_by_value_then_relevance(valueno sort_key, bool reverse)
Set the sorting to be by value, then by relevance for documents with the same value.
void set_query(const Query &query, termcount query_length=0)
Set the query.
void set_sort_by_relevance_then_value(valueno sort_key, bool reverse)
Set the sorting to be by relevance then value.
void set_sort_by_relevance()
Set the sorting to be by relevance only.
void set_sort_by_value(valueno sort_key, bool reverse)
Set the sorting to be by value only.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Virtual base class for key making functors.
Iterator over a Xapian::MSet.
double get_weight() const
Get the weight for the current position.
Class representing a list of search results.
void sort_by_relevance()
Sorts the list of documents in MSet according to their weights.
Xapian::doccount size() const
Return number of items in this MSet object.
double get_max_possible() const
The maximum possible weight any document could achieve.
void replace_weights(Iterator first, Iterator last)
Assigns new weights and updates MSet.
MSetIterator begin() const
Return iterator pointing to the first item in this MSet.
double get_max_attained() const
The maximum weight attained by any document.
MSetIterator end() const
Return iterator pointing to just after the last item in this MSet.
KeyMaker subclass which combines several values.
void add_value(Xapian::valueno slot, bool reverse=false, std::string_view defvalue={})
Add a value slot to the list to build a key from.
Class representing a query.
UnimplementedError indicates an attempt to use an unimplemented feature.
This class provides read/write access to a database.
Xapian::docid add_document(const Xapian::Document &doc)
Add a document to the database.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
#define FAIL_TEST(MSG)
Fail the current testcase with message MSG.
#define TEST_EQUAL(a, b)
Test for equality of two things.
#define TEST_EQUAL_DOUBLE(a, b)
Test two doubles for near equality.
#define TEST(a)
Test a condition, without an additional explanation for failure.
void mset_expect_order(const Xapian::MSet &A, Xapian::docid d1, Xapian::docid d2, Xapian::docid d3, Xapian::docid d4, Xapian::docid d5, Xapian::docid d6, Xapian::docid d7, Xapian::docid d8, Xapian::docid d9, Xapian::docid d10, Xapian::docid d11, Xapian::docid d12)
Xapian-specific test helper functions and macros.
#define TEST_EXCEPTION(TYPE, CODE)
Check that CODE throws exactly Xapian exception TYPE.
Public interfaces for the Xapian library.