xapian-core  1.4.21
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  * USA
21  */
22 
23 #include <config.h>
24 
26 
27 #include <xapian.h>
28 
29 #include "backendmanager.h"
30 #include "perftest.h"
31 #include "str.h"
32 #include "testrunner.h"
33 #include "testsuite.h"
34 #include "testutils.h"
35 
36 using namespace std;
37 
38 static void
39 builddb_valuestest1(Xapian::WritableDatabase &db, const string & dbname)
40 {
41  logger.testcase_begin(dbname);
42  unsigned int runsize = 1000000;
43 
44  // Rebuild the database.
45  std::map<std::string, std::string> params;
46  params["runsize"] = str(runsize);
47  logger.indexing_begin(dbname, params);
48  for (unsigned int i = 0; i < runsize; ++i) {
49  unsigned int v = i % 100;
50  Xapian::Document doc;
51  doc.set_data("test document " + str(i));
52  doc.add_term("foo");
53  string vs = str(v);
54  if (vs.size() == 1) vs = "0" + vs;
55  doc.add_value(0, vs);
56  doc.add_term("F" + vs);
57  doc.add_term("Q" + str(i));
58  for (int j = 0; j != 100; ++j)
59  doc.add_term("J" + str(j));
60  db.replace_document(i + 10, doc);
62  }
63  db.commit();
66 }
67 
68 // Test the performance of a ValueSetMatchDecider, compared to a Value range operator.
69 DEFINE_TESTCASE(valuesetmatchdecider1, writable && !remote && !inmemory) {
71  db = backendmanager->get_database("valuestest1", builddb_valuestest1,
72  "valuestest1");
73 
74  logger.testcase_begin("valuesetmatchdecider1");
75  Xapian::Enquire enquire(db);
76  Xapian::doccount runsize = db.get_doccount();
77 
78  Xapian::Query query("foo");
79  logger.searching_start("No match decider");
81  enquire.set_query(query);
82  Xapian::MSet mset = enquire.get_mset(0, 10);
83  logger.search_end(query, mset);
84  TEST(mset.size() == 10);
85  TEST(mset.get_matches_lower_bound() <= runsize);
86  TEST(mset.get_matches_upper_bound() <= runsize);
87 
89  mset = enquire.get_mset(0, 10);
90  logger.search_end(query, mset);
91  TEST(mset.size() == 10);
92  TEST(mset.get_matches_lower_bound() <= runsize);
94 
95  Xapian::ValueSetMatchDecider md(0, true);
96 
97  for (unsigned int i = 0; i < 100; ++i) {
98  string vs = str(i);
99  if (vs.size() == 1) vs = "0" + vs;
100  md.add_value(vs);
101 
102  logger.searching_start("Match decider accepting " + str(i + 1) + "%");
104  enquire.set_query(query);
105  mset = enquire.get_mset(0, 10, 0, NULL, &md);
106  logger.search_end(query, mset);
107  TEST_EQUAL(mset.size(), 10);
108  TEST_REL(mset.get_matches_lower_bound(),<=,runsize * (i + 1) / 100);
110 
113  logger.searching_start("Value range LE accepting " + str(i + 1) + "%");
114  Xapian::MSet mset2;
116  enquire.set_query(query2);
117  mset2 = enquire.get_mset(0, 10);
118  logger.search_end(query2, mset2);
119  TEST_EQUAL(mset2.size(), 10);
120  TEST_REL(mset2.get_matches_lower_bound(),<=,runsize * (i + 1) / 100);
121  test_mset_order_equal(mset, mset2);
123  }
124 
126 }
127 
128 // Test the performance of an AllDocsIterator.
129 DEFINE_TESTCASE(alldocsiter1, writable && !remote && !inmemory) {
130  Xapian::Database db;
131  db = backendmanager->get_database("valuestest1", builddb_valuestest1,
132  "valuestest1");
133 
134  logger.testcase_begin("alldocsiter1");
135 
136  logger.searching_start("AllDocsPostingIterator, full iteration");
140  while (begin != end) {
141  ++begin;
142  }
144 
146 
148 }
Xapian::doccount size() const
Return number of items in this MSet object.
Definition: omenquire.cc:318
Run multiple tests for different backends.
void add_value(Xapian::valueno slot, const std::string &value)
Add a new value.
Definition: omdocument.cc:107
MatchDecider filtering results based on whether document values are in a user-defined set...
#define TEST(a)
Test a condition, without an additional explanation for failure.
Definition: testsuite.h:275
This class is used to access a database, or a group of databases.
Definition: database.h:68
Xapian::Database get_database(const std::vector< std::string > &files)
Get a database instance of the current type.
void searching_start(const std::string &description)
Log the start of a search run.
Definition: perftest.cc:355
void search_start()
Log the start of a search.
Definition: perftest.cc:366
Xapian::doccount get_matches_lower_bound() const
Lower bound on the total number of matching documents.
Definition: omenquire.cc:246
performance tests for Xapian.
void indexing_add()
Log the addition of a document in an indexing run.
Definition: perftest.cc:329
a generic test suite engine
void add_value(const std::string &value)
Add a value to the test set.
Class representing a list of search results.
Definition: mset.h:44
PerfTestLogger logger
Definition: perftest.cc:52
STL namespace.
MSet get_mset(Xapian::doccount first, Xapian::doccount maxitems, Xapian::doccount checkatleast=0, const RSet *omrset=0, const MatchDecider *mdecider=0) const
Get (a portion of) the match set for the current query.
Definition: omenquire.cc:932
Convert types to std::string.
void replace_document(Xapian::docid did, const Xapian::Document &document)
Replace a given document in the database.
Definition: omdatabase.cc:952
Xapian::doccount get_doccount() const
Get the number of documents in the database.
Definition: omdatabase.cc:267
void testcase_begin(const std::string &testcase)
Start a testcase.
Definition: perftest.cc:400
Xapian::doccount get_matches_upper_bound() const
Upper bound on the total number of matching documents.
Definition: omenquire.cc:262
#define TEST_REL(A, REL, B)
Test a relation holds,e.g. TEST_REL(a,>,b);.
Definition: testmacros.h:32
Class for iterating over a list of terms.
Base class for backend handling in test harness.
void test_mset_order_equal(const Xapian::MSet &mset1, const Xapian::MSet &mset2)
Definition: testutils.cc:234
This class provides read/write access to a database.
Definition: database.h:785
Public interfaces for the Xapian library.
Match like OP_AND but only taking weight from the first subquery.
Definition: query.h:128
BackendManager * backendmanager
backendmanager is global so that it can be accessed by individual tests.
Definition: testrunner.cc:42
string str(int value)
Convert int to std::string.
Definition: str.cc:90
Match only documents where a value slot is <= a given value.
Definition: query.h:231
void commit()
Commit any pending modifications made to the database.
Definition: omdatabase.cc:857
void set_query(const Xapian::Query &query, Xapian::termcount qlen=0)
Set the query to run.
Definition: omenquire.cc:793
void indexing_end()
Log the end of an indexing run.
Definition: perftest.cc:345
static void builddb_valuestest1(Xapian::WritableDatabase &db, const string &dbname)
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:63
DEFINE_TESTCASE(valuesetmatchdecider1, writable &&!remote &&!inmemory)
This class provides an interface to the information retrieval system for the purpose of searching...
Definition: enquire.h:152
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
void search_end(const Xapian::Query &query, const Xapian::MSet &mset)
Log the completion of a search.
Definition: perftest.cc:372
Xapian-specific test helper functions and macros.
void searching_end()
Log the end of a search run.
Definition: perftest.cc:391
void testcase_end()
End a testcase.
Definition: perftest.cc:410
Class representing a query.
Definition: query.h:46
#define TEST_EQUAL(a, b)
Test for equality of two things.
Definition: testsuite.h:278
PostingIterator postlist_end(const std::string &) const
Corresponding end iterator to postlist_begin().
Definition: database.h:225
void set_data(const std::string &data)
Set data stored in the document.
Definition: omdocument.cc:78
A handle representing a document in a Xapian database.
Definition: document.h:61
PostingIterator postlist_begin(const std::string &tname) const
An iterator pointing to the start of the postlist for a given term.
Definition: omdatabase.cc:162
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:284
void add_term(const std::string &tname, Xapian::termcount wdfinc=1)
Add a term to the document, without positional information.
Definition: omdocument.cc:140