xapian-core  2.0.0
perftest_matchdecider.cc
Go to the documentation of this file.
1 
4 /* Copyright 2008 Lemur Consulting Ltd
5  * Copyright 2009,2015 Olly Betts
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <config.h>
23 
25 
26 #include <xapian.h>
27 
28 #include "backendmanager.h"
29 #include "perftest.h"
30 #include "str.h"
31 #include "testrunner.h"
32 #include "testsuite.h"
33 #include "testutils.h"
34 
35 using namespace std;
36 
37 static void
38 builddb_valuestest1(Xapian::WritableDatabase &db, const string & dbname)
39 {
40  logger.testcase_begin(dbname);
41  unsigned int runsize = 1000000;
42 
43  // Rebuild the database.
44  std::map<std::string, std::string> params;
45  params["runsize"] = str(runsize);
46  logger.indexing_begin(dbname, params);
47  for (unsigned int i = 0; i < runsize; ++i) {
48  unsigned int v = i % 100;
49  Xapian::Document doc;
50  doc.set_data("test document " + str(i));
51  doc.add_term("foo");
52  string vs = str(v);
53  if (vs.size() == 1) vs = "0" + vs;
54  doc.add_value(0, vs);
55  doc.add_term("F" + vs);
56  doc.add_term("Q" + str(i));
57  for (int j = 0; j != 100; ++j)
58  doc.add_term("J" + str(j));
59  db.replace_document(i + 10, doc);
61  }
62  db.commit();
65 }
66 
67 // Test the performance of a ValueSetMatchDecider, compared to a Value range operator.
68 DEFINE_TESTCASE(valuesetmatchdecider1, writable && !remote && !inmemory) {
70  db = backendmanager->get_database("valuestest1", builddb_valuestest1,
71  "valuestest1");
72 
73  logger.testcase_begin("valuesetmatchdecider1");
74  Xapian::Enquire enquire(db);
75  Xapian::doccount runsize = db.get_doccount();
76 
77  Xapian::Query query("foo");
78  logger.searching_start("No match decider");
80  enquire.set_query(query);
81  Xapian::MSet mset = enquire.get_mset(0, 10);
82  logger.search_end(query, mset);
83  TEST(mset.size() == 10);
84  TEST(mset.get_matches_lower_bound() <= runsize);
85  TEST(mset.get_matches_upper_bound() <= runsize);
86 
88  mset = enquire.get_mset(0, 10);
89  logger.search_end(query, mset);
90  TEST(mset.size() == 10);
91  TEST(mset.get_matches_lower_bound() <= runsize);
93 
94  Xapian::ValueSetMatchDecider md(0, true);
95 
96  for (unsigned int i = 0; i < 100; ++i) {
97  string vs = str(i);
98  if (vs.size() == 1) vs = "0" + vs;
99  md.add_value(vs);
100 
101  logger.searching_start("Match decider accepting " + str(i + 1) + "%");
103  enquire.set_query(query);
104  mset = enquire.get_mset(0, 10, 0, NULL, &md);
105  logger.search_end(query, mset);
106  TEST_EQUAL(mset.size(), 10);
107  TEST_REL(mset.get_matches_lower_bound(),<=,runsize * (i + 1) / 100);
109 
112  logger.searching_start("Value range LE accepting " + str(i + 1) + "%");
113  Xapian::MSet mset2;
115  enquire.set_query(query2);
116  mset2 = enquire.get_mset(0, 10);
117  logger.search_end(query2, mset2);
118  TEST_EQUAL(mset2.size(), 10);
119  TEST_REL(mset2.get_matches_lower_bound(),<=,runsize * (i + 1) / 100);
120  test_mset_order_equal(mset, mset2);
122  }
123 
125 }
126 
127 // Test the performance of an AllDocsIterator.
128 DEFINE_TESTCASE(alldocsiter1, writable && !remote && !inmemory) {
129  Xapian::Database db;
130  db = backendmanager->get_database("valuestest1", builddb_valuestest1,
131  "valuestest1");
132 
133  logger.testcase_begin("alldocsiter1");
134 
135  logger.searching_start("AllDocsPostingIterator, full iteration");
139  while (begin != end) {
140  ++begin;
141  }
143 
145 
147 }
static Xapian::Query query(Xapian::Query::op op, const string &t1=string(), const string &t2=string(), const string &t3=string(), const string &t4=string(), const string &t5=string(), const string &t6=string(), const string &t7=string(), const string &t8=string(), const string &t9=string(), const string &t10=string())
Definition: api_anydb.cc:62
Base class for backend handling in test harness.
Xapian::Database get_database(const std::vector< std::string > &files)
Get a database instance of the current type.
void indexing_begin(const std::string &dbname, const std::map< std::string, std::string > &params)
Log the start of an indexing run.
Definition: perftest.cc:293
void testcase_end()
End a testcase.
Definition: perftest.cc:463
void search_end(const Xapian::Query &query, const Xapian::MSet &mset)
Log the completion of a search.
Definition: perftest.cc:381
void searching_end()
Log the end of a search run.
Definition: perftest.cc:400
void search_start()
Log the start of a search.
Definition: perftest.cc:375
void indexing_end()
Log the end of an indexing run.
Definition: perftest.cc:354
void searching_start(const std::string &description)
Log the start of a search run.
Definition: perftest.cc:364
void testcase_begin(const std::string &testcase)
Start a testcase.
Definition: perftest.cc:453
void indexing_add()
Log the addition of a document in an indexing run.
Definition: perftest.cc:338
An indexed database of documents.
Definition: database.h:75
PostingIterator postlist_begin(std::string_view term) const
Start iterating the postings of a term.
Definition: database.cc:192
Xapian::doccount get_doccount() const
Get the number of documents in the database.
Definition: database.cc:233
PostingIterator postlist_end(std::string_view) const noexcept
End iterator corresponding to postlist_begin().
Definition: database.h:258
Class representing a document.
Definition: document.h:64
void set_data(std::string_view data)
Set the document data.
Definition: document.cc:81
void add_term(std::string_view term, Xapian::termcount wdf_inc=1)
Add a term to this document.
Definition: document.cc:87
void add_value(Xapian::valueno slot, std::string_view value)
Add a value to a slot in this document.
Definition: document.cc:191
Querying session.
Definition: enquire.h:57
MSet get_mset(doccount first, doccount maxitems, doccount checkatleast=0, const RSet *rset=NULL, const MatchDecider *mdecider=NULL) const
Run the query.
Definition: enquire.cc:200
void set_query(const Query &query, termcount query_length=0)
Set the query.
Definition: enquire.cc:72
Class representing a list of search results.
Definition: mset.h:46
Xapian::doccount size() const
Return number of items in this MSet object.
Definition: mset.cc:374
Xapian::doccount get_matches_upper_bound() const
Upper bound on the total number of matching documents.
Definition: mset.cc:334
Xapian::doccount get_matches_lower_bound() const
Lower bound on the total number of matching documents.
Definition: mset.cc:318
Class for iterating over a list of terms.
Class representing a query.
Definition: query.h:45
@ OP_FILTER
Match like OP_AND but only taking weight from the first subquery.
Definition: query.h:128
@ OP_VALUE_LE
Match only documents where a value slot is <= a given value.
Definition: query.h:231
MatchDecider filtering results based on whether document values are in a user-defined set.
void add_value(const std::string &value)
Add a value to the test set.
This class provides read/write access to a database.
Definition: database.h:964
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a document in the database.
Definition: database.cc:582
void commit()
Commit pending modifications.
Definition: database.cc:543
string str(int value)
Convert int to std::string.
Definition: str.cc:91
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:37
PerfTestLogger logger
Definition: perftest.cc:51
performance tests for Xapian.
static void builddb_valuestest1(Xapian::WritableDatabase &db, const string &dbname)
DEFINE_TESTCASE(valuesetmatchdecider1, writable &&!remote &&!inmemory)
Convert types to std::string.
#define TEST_REL(A, REL, B)
Test a relation holds,e.g. TEST_REL(a,>,b);.
Definition: testmacros.h:35
BackendManager * backendmanager
backendmanager is global so that it can be accessed by individual tests.
Definition: testrunner.cc:41
Run multiple tests for different backends.
a generic test suite engine
#define TEST_EQUAL(a, b)
Test for equality of two things.
Definition: testsuite.h:276
#define TEST(a)
Test a condition, without an additional explanation for failure.
Definition: testsuite.h:273
void test_mset_order_equal(const Xapian::MSet &mset1, const Xapian::MSet &mset2)
Definition: testutils.cc:233
Xapian-specific test helper functions and macros.
Public interfaces for the Xapian library.