LCOV - code coverage report
Current view: top level - tests - api_anydb.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 1454 1454 100.0 %
Date: 2019-06-30 05:20:33 Functions: 87 87 100.0 %
Branches: 2707 14029 19.3 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_anydb.cc
       2                 :            :  * @brief tests which work with any backend
       3                 :            :  */
       4                 :            : /* Copyright 1999,2000,2001 BrightStation PLC
       5                 :            :  * Copyright 2002 Ananova Ltd
       6                 :            :  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2015,2016,2017 Olly Betts
       7                 :            :  * Copyright 2006,2008 Lemur Consulting Ltd
       8                 :            :  * Copyright 2011 Action Without Borders
       9                 :            :  *
      10                 :            :  * This program is free software; you can redistribute it and/or
      11                 :            :  * modify it under the terms of the GNU General Public License as
      12                 :            :  * published by the Free Software Foundation; either version 2 of the
      13                 :            :  * License, or (at your option) any later version.
      14                 :            :  *
      15                 :            :  * This program is distributed in the hope that it will be useful,
      16                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      17                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18                 :            :  * GNU General Public License for more details.
      19                 :            :  *
      20                 :            :  * You should have received a copy of the GNU General Public License
      21                 :            :  * along with this program; if not, write to the Free Software
      22                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      23                 :            :  * USA
      24                 :            :  */
      25                 :            : 
      26                 :            : #include <config.h>
      27                 :            : 
      28                 :            : #include "api_anydb.h"
      29                 :            : 
      30                 :            : #include <algorithm>
      31                 :            : #include <string>
      32                 :            : 
      33                 :            : #define XAPIAN_DEPRECATED(X) X
      34                 :            : #include <xapian.h>
      35                 :            : #include "backendmanager_local.h"
      36                 :            : #include "testsuite.h"
      37                 :            : #include "testutils.h"
      38                 :            : 
      39                 :            : #include "apitest.h"
      40                 :            : 
      41                 :            : #include <list>
      42                 :            : 
      43                 :            : using namespace std;
      44                 :            : 
      45                 :            : static void
      46                 :         14 : print_mset_weights(const Xapian::MSet &mset)
      47                 :            : {
      48         [ +  - ]:         14 :     Xapian::MSetIterator i = mset.begin();
      49 [ +  - ][ +  + ]:         77 :     for ( ; i != mset.end(); ++i) {
      50 [ +  - ][ +  - ]:         63 :         tout << " " << i.get_weight();
                 [ +  - ]
      51                 :         14 :     }
      52                 :         14 : }
      53                 :            : 
      54                 :            : static void
      55                 :         28 : print_mset_percentages(const Xapian::MSet &mset)
      56                 :            : {
      57         [ +  - ]:         28 :     Xapian::MSetIterator i = mset.begin();
      58 [ +  - ][ +  + ]:        168 :     for ( ; i != mset.end(); ++i) {
      59 [ +  - ][ +  - ]:        140 :         tout << " " << mset.convert_to_percent(i);
                 [ +  - ]
      60                 :         28 :     }
      61                 :         28 : }
      62                 :            : 
      63                 :            : static Xapian::Query
      64                 :        142 : query(Xapian::Query::op op,
      65                 :            :       const string & t1 = string(), const string & t2 = string(),
      66                 :            :       const string & t3 = string(), const string & t4 = string(),
      67                 :            :       const string & t5 = string(), const string & t6 = string(),
      68                 :            :       const string & t7 = string(), const string & t8 = string(),
      69                 :            :       const string & t9 = string(), const string & t10 = string())
      70                 :            : {
      71                 :        142 :     vector<string> v;
      72 [ +  - ][ +  - ]:        284 :     Xapian::Stem stemmer("english");
      73 [ +  - ][ +  - ]:        142 :     if (!t1.empty()) v.push_back(stemmer(t1));
                 [ +  - ]
      74 [ +  + ][ +  - ]:        142 :     if (!t2.empty()) v.push_back(stemmer(t2));
                 [ +  - ]
      75 [ +  + ][ +  - ]:        142 :     if (!t3.empty()) v.push_back(stemmer(t3));
                 [ +  - ]
      76 [ +  + ][ +  - ]:        142 :     if (!t4.empty()) v.push_back(stemmer(t4));
                 [ +  - ]
      77 [ -  + ][ #  # ]:        142 :     if (!t5.empty()) v.push_back(stemmer(t5));
                 [ #  # ]
      78 [ -  + ][ #  # ]:        142 :     if (!t6.empty()) v.push_back(stemmer(t6));
                 [ #  # ]
      79 [ -  + ][ #  # ]:        142 :     if (!t7.empty()) v.push_back(stemmer(t7));
                 [ #  # ]
      80 [ -  + ][ #  # ]:        142 :     if (!t8.empty()) v.push_back(stemmer(t8));
                 [ #  # ]
      81 [ -  + ][ #  # ]:        142 :     if (!t9.empty()) v.push_back(stemmer(t9));
                 [ #  # ]
      82 [ -  + ][ #  # ]:        142 :     if (!t10.empty()) v.push_back(stemmer(t10));
                 [ #  # ]
      83         [ +  - ]:        284 :     return Xapian::Query(op, v.begin(), v.end());
      84                 :            : }
      85                 :            : 
      86                 :            : static Xapian::Query
      87                 :         14 : query(Xapian::Query::op op, Xapian::termcount parameter,
      88                 :            :       const string & t1 = string(), const string & t2 = string(),
      89                 :            :       const string & t3 = string(), const string & t4 = string(),
      90                 :            :       const string & t5 = string(), const string & t6 = string(),
      91                 :            :       const string & t7 = string(), const string & t8 = string(),
      92                 :            :       const string & t9 = string(), const string & t10 = string())
      93                 :            : {
      94                 :         14 :     vector<string> v;
      95 [ +  - ][ +  - ]:         28 :     Xapian::Stem stemmer("english");
      96 [ +  - ][ +  - ]:         14 :     if (!t1.empty()) v.push_back(stemmer(t1));
                 [ +  - ]
      97 [ +  - ][ +  - ]:         14 :     if (!t2.empty()) v.push_back(stemmer(t2));
                 [ +  - ]
      98 [ +  + ][ +  - ]:         14 :     if (!t3.empty()) v.push_back(stemmer(t3));
                 [ +  - ]
      99 [ -  + ][ #  # ]:         14 :     if (!t4.empty()) v.push_back(stemmer(t4));
                 [ #  # ]
     100 [ -  + ][ #  # ]:         14 :     if (!t5.empty()) v.push_back(stemmer(t5));
                 [ #  # ]
     101 [ -  + ][ #  # ]:         14 :     if (!t6.empty()) v.push_back(stemmer(t6));
                 [ #  # ]
     102 [ -  + ][ #  # ]:         14 :     if (!t7.empty()) v.push_back(stemmer(t7));
                 [ #  # ]
     103 [ -  + ][ #  # ]:         14 :     if (!t8.empty()) v.push_back(stemmer(t8));
                 [ #  # ]
     104 [ -  + ][ #  # ]:         14 :     if (!t9.empty()) v.push_back(stemmer(t9));
                 [ #  # ]
     105 [ -  + ][ #  # ]:         14 :     if (!t10.empty()) v.push_back(stemmer(t10));
                 [ #  # ]
     106         [ +  - ]:         28 :     return Xapian::Query(op, v.begin(), v.end(), parameter);
     107                 :            : }
     108                 :            : 
     109                 :            : static Xapian::Query
     110                 :         84 : query(const string &t)
     111                 :            : {
     112 [ +  - ][ +  - ]:         84 :     return Xapian::Query(Xapian::Stem("english")(t));
         [ +  - ][ +  - ]
     113                 :            : }
     114                 :            : 
     115                 :            : // #######################################################################
     116                 :            : // # Tests start here
     117                 :            : 
     118                 :            : // tests that the backend doesn't return zero docids
     119                 :          7 : DEFINE_TESTCASE(zerodocid1, backend) {
     120                 :            :     // open the database (in this case a simple text file
     121                 :            :     // we prepared earlier)
     122                 :            : 
     123 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_onedoc"));
     124                 :            : 
     125         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
     126                 :            : 
     127                 :            :     // make a simple query, with one word in it - "word".
     128 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("word"));
                 [ +  - ]
     129                 :            : 
     130                 :            :     // retrieve the top ten results (we only expect one)
     131         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     132                 :            : 
     133                 :            :     // We've done the query, now check that the result is what
     134                 :            :     // we expect (1 document, with non-zero docid)
     135 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     136                 :            : 
     137 [ +  - ][ +  - ]:          7 :     TEST_AND_EXPLAIN(*(mymset.begin()) != 0,
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     138                 :            :                      "A query on a database returned a zero docid");
     139                 :            : 
     140                 :          7 :     return true;
     141                 :            : }
     142                 :            : 
     143                 :            : // tests that an empty query returns no matches
     144                 :          7 : DEFINE_TESTCASE(emptyquery1, backend) {
     145 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     146                 :            : 
     147         [ +  - ]:          7 :     enquire.set_query(Xapian::Query());
     148         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     149 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     150 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     151 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     152 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     153 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     154 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     155 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     156                 :            : 
     157                 :         14 :     vector<Xapian::Query> v;
     158 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query(Xapian::Query::OP_AND, v.begin(), v.end()));
     159 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     160 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     161 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     162 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     163 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     164 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     165 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     166 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     167                 :            : 
     168                 :          7 :     return true;
     169                 :            : }
     170                 :            : 
     171                 :            : // tests the document count for a simple query
     172                 :          7 : DEFINE_TESTCASE(simplequery1, backend) {
     173 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     174 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("word"));
                 [ +  - ]
     175         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     176 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     177                 :          7 :     return true;
     178                 :            : }
     179                 :            : 
     180                 :            : // tests for the right documents and weights returned with simple query
     181                 :          7 : DEFINE_TESTCASE(simplequery2, backend) {
     182                 :            :     // open the database (in this case a simple text file
     183                 :            :     // we prepared earlier)
     184 [ +  - ][ +  - ]:          7 :     Xapian::Database db = get_database("apitest_simpledata");
     185         [ +  - ]:         14 :     Xapian::Enquire enquire(db);
     186 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("word"));
                 [ +  - ]
     187                 :            : 
     188                 :            :     // retrieve the top results
     189         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     190                 :            : 
     191                 :            :     // We've done the query, now check that the result is what
     192                 :            :     // we expect (documents 2 and 4)
     193         [ +  - ]:          7 :     mset_expect_order(mymset, 2, 4);
     194                 :            : 
     195                 :            :     // Check the weights
     196         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     197                 :            :     // These weights are for BM25Weight(1,0,1,0.5,0.5)
     198 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(i.get_weight(), 1.04648168717725);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     199         [ +  - ]:          7 :     i++;
     200 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(i.get_weight(), 0.640987686595914);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     201                 :            : 
     202                 :          7 :     return true;
     203                 :            : }
     204                 :            : 
     205                 :            : // tests for the right document count for another simple query
     206                 :          7 : DEFINE_TESTCASE(simplequery3, backend) {
     207 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     208 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
     209         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     210                 :            : 
     211                 :            :     // Check that 6 documents were returned.
     212 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 6);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     213                 :            : 
     214                 :          7 :     return true;
     215                 :            : }
     216                 :            : 
     217                 :            : // multidb2 no longer exists.
     218                 :            : 
     219                 :            : // test that a multidb with 2 dbs query returns correct docids
     220                 :          6 : DEFINE_TESTCASE(multidb3, backend && !multi) {
     221 [ +  - ][ +  - ]:          6 :     Xapian::Database mydb2(get_database("apitest_simpledata"));
     222 [ +  - ][ +  - ]:          6 :     mydb2.add_database(get_database("apitest_simpledata2"));
                 [ +  - ]
     223         [ +  - ]:         12 :     Xapian::Enquire enquire(mydb2);
     224                 :            : 
     225                 :            :     // make a query
     226 [ +  - ][ +  - ]:         12 :     Xapian::Query myquery = query(Xapian::Query::OP_OR, "inmemory", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     227         [ +  - ]:          6 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     228         [ +  - ]:          6 :     enquire.set_query(myquery);
     229                 :            : 
     230                 :            :     // retrieve the top ten results
     231         [ +  - ]:         12 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     232         [ +  - ]:          6 :     mset_expect_order(mymset, 2, 3, 7);
     233                 :            : 
     234                 :          6 :     return true;
     235                 :            : }
     236                 :            : 
     237                 :            : // test that a multidb with 3 dbs query returns correct docids
     238                 :          6 : DEFINE_TESTCASE(multidb4, backend && !multi) {
     239 [ +  - ][ +  - ]:          6 :     Xapian::Database mydb2(get_database("apitest_simpledata"));
     240 [ +  - ][ +  - ]:          6 :     mydb2.add_database(get_database("apitest_simpledata2"));
                 [ +  - ]
     241 [ +  - ][ +  - ]:          6 :     mydb2.add_database(get_database("apitest_termorder"));
                 [ +  - ]
     242         [ +  - ]:         12 :     Xapian::Enquire enquire(mydb2);
     243                 :            : 
     244                 :            :     // make a query
     245 [ +  - ][ +  - ]:         12 :     Xapian::Query myquery = query(Xapian::Query::OP_OR, "inmemory", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     246         [ +  - ]:          6 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     247         [ +  - ]:          6 :     enquire.set_query(myquery);
     248                 :            : 
     249                 :            :     // retrieve the top ten results
     250         [ +  - ]:         12 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     251         [ +  - ]:          6 :     mset_expect_order(mymset, 2, 3, 4, 10);
     252                 :            : 
     253                 :          6 :     return true;
     254                 :            : }
     255                 :            : 
     256                 :            : // tests MultiPostList::skip_to().
     257                 :          6 : DEFINE_TESTCASE(multidb5, backend && !multi) {
     258 [ +  - ][ +  - ]:          6 :     Xapian::Database mydb2(get_database("apitest_simpledata"));
     259 [ +  - ][ +  - ]:          6 :     mydb2.add_database(get_database("apitest_simpledata2"));
                 [ +  - ]
     260         [ +  - ]:         12 :     Xapian::Enquire enquire(mydb2);
     261                 :            : 
     262                 :            :     // make a query
     263 [ +  - ][ +  - ]:         12 :     Xapian::Query myquery = query(Xapian::Query::OP_AND, "inmemory", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     264         [ +  - ]:          6 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     265         [ +  - ]:          6 :     enquire.set_query(myquery);
     266                 :            : 
     267                 :            :     // retrieve the top ten results
     268         [ +  - ]:         12 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     269         [ +  - ]:          6 :     mset_expect_order(mymset, 2);
     270                 :            : 
     271                 :          6 :     return true;
     272                 :            : }
     273                 :            : 
     274                 :            : // tests that when specifying maxitems to get_mset, no more than
     275                 :            : // that are returned.
     276                 :          7 : DEFINE_TESTCASE(msetmaxitems1, backend) {
     277 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     278 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
     279         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 1);
     280 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     281                 :            : 
     282 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 5);
     283 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     284                 :            : 
     285                 :          7 :     return true;
     286                 :            : }
     287                 :            : 
     288                 :            : // tests the returned weights are as expected (regression test for remote
     289                 :            : // backend which was using the average weight rather than the actual document
     290                 :            : // weight for computing weights - fixed in 1.0.0).
     291                 :          7 : DEFINE_TESTCASE(expandweights1, backend) {
     292 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     293 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     294                 :            : 
     295         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     296                 :            : 
     297         [ +  - ]:         14 :     Xapian::RSet myrset;
     298         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     299 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     300 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     301                 :            : 
     302         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(3, myrset, enquire.USE_EXACT_TERMFREQ);
     303 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     304 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     305 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     306 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     307 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     308                 :            : 
     309                 :            :     // Test non-default k too.
     310 [ +  - ][ +  - ]:          7 :     enquire.set_expansion_scheme("trad", 2.0);
     311 [ +  - ][ +  - ]:          7 :     eset = enquire.get_eset(3, myrset, enquire.USE_EXACT_TERMFREQ);
     312 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     313 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     314 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[0].get_weight(), 5.88109547674955);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     315 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[1].get_weight(), 5.88109547674955);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     316 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[2].get_weight(), 5.44473599216144);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     317                 :            : 
     318                 :          7 :     return true;
     319                 :            : }
     320                 :            : 
     321                 :            : // Just like test_expandweights1 but without USE_EXACT_TERMFREQ.
     322                 :          7 : DEFINE_TESTCASE(expandweights2, backend) {
     323 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     324 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     325                 :            : 
     326         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     327                 :            : 
     328         [ +  - ]:         14 :     Xapian::RSet myrset;
     329         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     330 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     331 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     332                 :            : 
     333         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(3, myrset);
     334 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     335 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     336 [ +  - ][ +  + ]:          7 :     if (!startswith(get_dbtype(), "multi")) {
     337                 :            :         // For a single database, the weights should be the same with or
     338                 :            :         // without USE_EXACT_TERMFREQ.
     339 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     340 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     341 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     342                 :            :     } else {
     343                 :            :         // For multiple databases, we expect that using USE_EXACT_TERMFREQ
     344                 :            :         // will result in different weights in some cases.
     345 [ +  - ][ +  - ]:          1 :         TEST_NOT_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     346 [ +  - ][ +  - ]:          1 :         TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     347 [ +  - ][ +  - ]:          1 :         TEST_NOT_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     348                 :            :     }
     349                 :            : 
     350                 :          7 :     return true;
     351                 :            : }
     352                 :            : 
     353                 :          7 : DEFINE_TESTCASE(expandweights3, backend) {
     354 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     355 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     356                 :            : 
     357         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     358                 :            : 
     359         [ +  - ]:         14 :     Xapian::RSet myrset;
     360         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     361 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     362 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     363                 :            : 
     364                 :            :     // Set min_wt to 0.0
     365         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(50, myrset, 0, 0, 0.0);
     366 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 50);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     367 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     368 [ +  - ][ +  + ]:          7 :     if (!startswith(get_dbtype(), "multi")) {
     369                 :            :         // For a single database, the weights should be the same with or
     370                 :            :         // without USE_EXACT_TERMFREQ.
     371 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     372 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     373 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     374                 :            :     } else {
     375                 :            :         // For multiple databases, we expect that using USE_EXACT_TERMFREQ
     376                 :            :         // will result in different weights in some cases.
     377 [ +  - ][ +  - ]:          1 :         TEST_NOT_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     378 [ +  - ][ +  - ]:          1 :         TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     379 [ +  - ][ +  - ]:          1 :         TEST_NOT_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     380                 :            :     }
     381 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.back().get_weight(),>=,0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     382                 :            : 
     383                 :          7 :     return true;
     384                 :            : }
     385                 :            : 
     386                 :            : // tests that negative weights are returned
     387                 :          7 : DEFINE_TESTCASE(expandweights4, backend) {
     388 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     389 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("paragraph"));
                 [ +  - ]
     390                 :            : 
     391         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     392                 :            : 
     393         [ +  - ]:         14 :     Xapian::RSet myrset;
     394         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     395 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     396 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     397                 :            : 
     398         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(37, myrset, 0, 0, -100);
     399                 :            :     // Now include negative weights
     400 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 37);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     401 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     402 [ +  - ][ +  - ]:          7 :     TEST_REL(eset[36].get_weight(), <, 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     403 [ +  - ][ +  - ]:          7 :     TEST_REL(eset[36].get_weight(), >=, -100);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     404                 :            : 
     405                 :          7 :     return true;
     406                 :            : }
     407                 :            : 
     408                 :            : // test for Bo1EWeight
     409                 :          7 : DEFINE_TESTCASE(expandweights5, backend) {
     410 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     411 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     412                 :            : 
     413         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     414                 :            : 
     415         [ +  - ]:         14 :     Xapian::RSet myrset;
     416         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     417 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     418 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     419                 :            : 
     420 [ +  - ][ +  - ]:          7 :     enquire.set_expansion_scheme("bo1");
     421         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(3, myrset);
     422                 :            : 
     423 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     424 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     425 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[0].get_weight(), 7.21765284821702);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     426 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.661623193760022);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     427 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[2].get_weight(), 5.58090119783738);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     428                 :            : 
     429                 :          7 :     return true;
     430                 :            : }
     431                 :            : 
     432                 :            : // test that "trad" can be set as an expansion scheme.
     433                 :          7 : DEFINE_TESTCASE(expandweights6, backend) {
     434 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     435 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     436                 :            : 
     437         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     438                 :            : 
     439         [ +  - ]:         14 :     Xapian::RSet myrset;
     440         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     441 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     442 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     443                 :            : 
     444 [ +  - ][ +  - ]:          7 :     enquire.set_expansion_scheme("trad");
     445         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(3, myrset, enquire.USE_EXACT_TERMFREQ);
     446                 :            : 
     447 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(eset.size(), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     448 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.get_ebound(), >=, eset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     449 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     450 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     451 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     452                 :            : 
     453                 :          7 :     return true;
     454                 :            : }
     455                 :            : 
     456                 :            : // test that invalid scheme names are not accepted
     457                 :          7 : DEFINE_TESTCASE(expandweights7, backend) {
     458 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     459                 :            : 
     460 [ +  - ][ +  - ]:          7 :     TEST_EXCEPTION(Xapian::InvalidArgumentError,
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
     461                 :            :                    enquire.set_expansion_scheme("no_such_scheme"));
     462                 :            : 
     463                 :          7 :     return true;
     464                 :            : }
     465                 :            : 
     466                 :            : // test that "expand_k" can be passed as a parameter to get_eset
     467                 :          7 : DEFINE_TESTCASE(expandweights8, backend) {
     468 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     469 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     470                 :            : 
     471         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     472                 :            : 
     473         [ +  - ]:         14 :     Xapian::RSet myrset;
     474         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     475 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     476 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     477                 :            : 
     478                 :            :     // Set expand_k to 1.0 and min_wt to 0
     479 [ +  - ][ +  - ]:          7 :     enquire.set_expansion_scheme("trad", 1.0);
     480         [ +  - ]:         14 :     Xapian::ESet eset = enquire.get_eset(50, myrset, 0, 0, 0);
     481 [ +  - ][ +  + ]:          7 :     if (!startswith(get_dbtype(), "multi")) {
     482                 :            :         // For a single database, the weights should be the same with or
     483                 :            :         // without USE_EXACT_TERMFREQ.
     484 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     485 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     486 [ +  - ][ +  - ]:          6 :         TEST_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     487                 :            :     } else {
     488                 :            :         // For multiple databases, we expect that using USE_EXACT_TERMFREQ
     489                 :            :         // will result in different weights in some cases.
     490 [ +  - ][ +  - ]:          1 :         TEST_NOT_EQUAL_DOUBLE(eset[0].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     491 [ +  - ][ +  - ]:          1 :         TEST_EQUAL_DOUBLE(eset[1].get_weight(), 6.08904001099445);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     492 [ +  - ][ +  - ]:          1 :         TEST_NOT_EQUAL_DOUBLE(eset[2].get_weight(), 4.73383620844021);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     493                 :            :     }
     494 [ +  - ][ +  - ]:          7 :     TEST_REL(eset.back().get_weight(),>=,0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     495                 :            : 
     496                 :          7 :     return true;
     497                 :            : }
     498                 :            : 
     499                 :            : // tests that when specifying maxitems to get_eset, no more than
     500                 :            : // that are returned.
     501                 :          7 : DEFINE_TESTCASE(expandmaxitems1, backend) {
     502 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     503 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     504                 :            : 
     505         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     506 [ +  - ][ +  - ]:          7 :     tout << "mymset.size() = " << mymset.size() << endl;
         [ +  - ][ +  - ]
     507 [ +  - ][ -  + ]:          7 :     TEST(mymset.size() >= 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     508                 :            : 
     509         [ +  - ]:         14 :     Xapian::RSet myrset;
     510         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     511 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     512 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     513                 :            : 
     514         [ +  - ]:         14 :     Xapian::ESet myeset = enquire.get_eset(1, myrset);
     515 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(myeset.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     516 [ +  - ][ +  - ]:          7 :     TEST_REL(myeset.get_ebound(), >=, myeset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     517                 :            : 
     518                 :          7 :     return true;
     519                 :            : }
     520                 :            : 
     521                 :            : // tests that a pure boolean query has all weights set to 0
     522                 :          7 : DEFINE_TESTCASE(boolquery1, backend) {
     523 [ +  - ][ +  - ]:          7 :     Xapian::Query myboolquery(query("this"));
     524                 :            : 
     525                 :            :     // open the database (in this case a simple text file
     526                 :            :     // we prepared earlier)
     527 [ +  - ][ +  - ]:         14 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     528         [ +  - ]:          7 :     enquire.set_query(myboolquery);
     529         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     530                 :            : 
     531                 :            :     // retrieve the top results
     532         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     533                 :            : 
     534 [ +  - ][ -  + ]:          7 :     TEST_NOT_EQUAL(mymset.size(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     535 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_max_possible(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     536 [ +  - ][ +  - ]:         49 :     for (Xapian::MSetIterator i = mymset.begin(); i != mymset.end(); ++i) {
                 [ +  + ]
     537 [ +  - ][ -  + ]:         42 :         TEST_EQUAL(i.get_weight(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     538                 :          7 :     }
     539                 :          7 :     return true;
     540                 :            : }
     541                 :            : 
     542                 :            : // tests that get_mset() specifying "this" works as expected
     543                 :          7 : DEFINE_TESTCASE(msetfirst1, backend) {
     544 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     545 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
     546         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 6);
     547         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(3, 3);
     548 [ +  - ][ -  + ]:          7 :     TEST(mset_range_is_same(mymset1, 3, mymset2, 0, 3));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     549                 :            : 
     550                 :            :     // Regression test - we weren't adjusting the index into items[] by
     551                 :            :     // firstitem in api/omenquire.cc.
     552 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1[5].get_document().get_data(),
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     553                 :            :                mymset2[2].get_document().get_data());
     554                 :          7 :     return true;
     555                 :            : }
     556                 :            : 
     557                 :            : // tests the converting-to-percent functions
     558                 :          7 : DEFINE_TESTCASE(topercent1, backend) {
     559 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     560 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
     561         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 20);
     562                 :            : 
     563                 :          7 :     int last_pct = 100;
     564         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     565 [ +  - ][ +  + ]:         49 :     for ( ; i != mymset.end(); ++i) {
     566         [ +  - ]:         42 :         int pct = mymset.convert_to_percent(i);
     567 [ +  - ][ -  + ]:         42 :         TEST_AND_EXPLAIN(pct == i.get_percent(),
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     568                 :            :                          "convert_to_%(msetitor) != convert_to_%(wt)");
     569 [ +  - ][ +  - ]:         42 :         TEST_AND_EXPLAIN(pct == mymset.convert_to_percent(i.get_weight()),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     570                 :            :                          "convert_to_%(msetitor) != convert_to_%(wt)");
     571 [ +  - ][ -  + ]:         42 :         TEST_AND_EXPLAIN(pct >= 0 && pct <= 100,
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     572                 :            :                          "percentage out of range: " << pct);
     573 [ -  + ][ #  # ]:         42 :         TEST_AND_EXPLAIN(pct <= last_pct, "percentage increased down mset");
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     574                 :         42 :         last_pct = pct;
     575                 :            :     }
     576                 :          7 :     return true;
     577                 :            : }
     578                 :            : 
     579                 :            : // tests the percentage values returned
     580                 :          7 : DEFINE_TESTCASE(topercent2, backend) {
     581 [ +  - ][ +  - ]:          7 :     BackendManagerLocal local_manager(test_driver::get_srcdir() + "/testdata/");
                 [ +  - ]
     582 [ +  - ][ +  - ]:         14 :     Xapian::Enquire localenq(local_manager.get_database("apitest_simpledata"));
                 [ +  - ]
     583 [ +  - ][ +  - ]:         14 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     584                 :            : 
     585                 :            :     int pct;
     586                 :            : 
     587                 :            :     // First, test a search in which the top document scores 100%.
     588 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
     589 [ +  - ][ +  - ]:          7 :     localenq.set_query(query("this"));
                 [ +  - ]
     590         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 20);
     591         [ +  - ]:         14 :     Xapian::MSet localmset = localenq.get_mset(0, 20);
     592                 :            : 
     593         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     594 [ +  - ][ -  + ]:          7 :     TEST(i != mymset.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     595         [ +  - ]:          7 :     pct = mymset.convert_to_percent(i);
     596 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(pct, 100);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     597                 :            : 
     598 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), localmset.get_matches_lower_bound());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     599 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), localmset.get_matches_upper_bound());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     600 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), localmset.get_matches_estimated());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     601 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(mymset.get_max_attained(), localmset.get_max_attained());
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     602 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.size(), localmset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     603 [ +  - ][ +  - ]:          7 :     TEST(mset_range_is_same(mymset, 0, localmset, 0, mymset.size()));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     604                 :            : 
     605                 :            :     // A search in which the top document doesn't have 100%
     606                 :            :     Xapian::Query q = query(Xapian::Query::OP_OR,
     607 [ +  - ][ +  - ]:         14 :                             "this", "line", "paragraph", "rubbish");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     608         [ +  - ]:          7 :     enquire.set_query(q);
     609         [ +  - ]:          7 :     localenq.set_query(q);
     610 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     611 [ +  - ][ +  - ]:          7 :     localmset = localenq.get_mset(0, 20);
     612                 :            : 
     613 [ +  - ][ +  - ]:          7 :     i = mymset.begin();
     614 [ +  - ][ -  + ]:          7 :     TEST(i != mymset.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     615         [ +  - ]:          7 :     pct = mymset.convert_to_percent(i);
     616 [ -  + ][ #  # ]:          7 :     TEST_REL(pct,>,60);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     617 [ -  + ][ #  # ]:          7 :     TEST_REL(pct,<,76);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     618                 :            : 
     619                 :          7 :     ++i;
     620                 :            : 
     621 [ +  - ][ -  + ]:          7 :     TEST(i != mymset.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     622         [ +  - ]:          7 :     pct = mymset.convert_to_percent(i);
     623 [ -  + ][ #  # ]:          7 :     TEST_REL(pct,>,40);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     624 [ -  + ][ #  # ]:          7 :     TEST_REL(pct,<,50);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     625                 :            : 
     626 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), localmset.get_matches_lower_bound());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     627 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), localmset.get_matches_upper_bound());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     628 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), localmset.get_matches_estimated());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     629 [ +  - ][ +  - ]:          7 :     TEST_EQUAL_DOUBLE(mymset.get_max_attained(), localmset.get_max_attained());
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     630 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset.size(), localmset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     631 [ +  - ][ +  - ]:          7 :     TEST(mset_range_is_same(mymset, 0, localmset, 0, mymset.size()));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     632                 :            : 
     633                 :          7 :     return true;
     634                 :            : }
     635                 :            : 
     636         [ -  + ]:         28 : class EvenParityExpandFunctor : public Xapian::ExpandDecider {
     637                 :            :   public:
     638                 :       1319 :     bool operator()(const string & tname) const {
     639                 :       1319 :         unsigned long sum = 0;
     640         [ +  + ]:       6705 :         for (unsigned ch : tname) {
     641                 :       5386 :             sum += ch;
     642                 :            :         }
     643                 :            : //      if (verbose) {
     644                 :            : //          tout << tname << "==> " << sum << "\n";
     645                 :            : //      }
     646                 :       1319 :         return (sum % 2) == 0;
     647                 :            :     }
     648                 :            : };
     649                 :            : 
     650                 :            : // tests the expand decision functor
     651                 :          7 : DEFINE_TESTCASE(expandfunctor1, backend) {
     652 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     653 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     654                 :            : 
     655         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     656 [ +  - ][ -  + ]:          7 :     TEST(mymset.size() >= 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     657                 :            : 
     658         [ +  - ]:         14 :     Xapian::RSet myrset;
     659         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     660 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     661 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     662                 :            : 
     663                 :         14 :     EvenParityExpandFunctor myfunctor;
     664                 :            : 
     665         [ +  - ]:         14 :     Xapian::ESet myeset_orig = enquire.get_eset(1000, myrset);
     666                 :          7 :     unsigned int neweset_size = 0;
     667         [ +  - ]:         14 :     Xapian::ESetIterator j = myeset_orig.begin();
     668 [ +  - ][ +  + ]:        432 :     for ( ; j != myeset_orig.end(); ++j) {
     669 [ +  - ][ +  - ]:        425 :         if (myfunctor(*j)) neweset_size++;
                 [ +  + ]
     670                 :            :     }
     671         [ +  - ]:         14 :     Xapian::ESet myeset = enquire.get_eset(neweset_size, myrset, &myfunctor);
     672                 :            : 
     673                 :            : #if 0
     674                 :            :     // Compare myeset with the hand-filtered version of myeset_orig.
     675                 :            :     if (verbose) {
     676                 :            :         tout << "orig_eset: ";
     677                 :            :         copy(myeset_orig.begin(), myeset_orig.end(),
     678                 :            :              ostream_iterator<Xapian::ESetItem>(tout, " "));
     679                 :            :         tout << "\n";
     680                 :            : 
     681                 :            :         tout << "new_eset: ";
     682                 :            :         copy(myeset.begin(), myeset.end(),
     683                 :            :              ostream_iterator<Xapian::ESetItem>(tout, " "));
     684                 :            :         tout << "\n";
     685                 :            :     }
     686                 :            : #endif
     687         [ +  - ]:         14 :     Xapian::ESetIterator orig = myeset_orig.begin();
     688         [ +  - ]:         14 :     Xapian::ESetIterator filt = myeset.begin();
     689 [ +  - ][ +  - ]:        184 :     for (; orig != myeset_orig.end() && filt != myeset.end(); ++orig, ++filt) {
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
           [ +  +  #  #  
                   #  # ]
     690                 :            :         // skip over items that shouldn't be in myeset
     691 [ +  - ][ +  - ]:        411 :         while (orig != myeset_orig.end() && !myfunctor(*orig)) {
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
         [ +  - ][ +  +  
             #  #  #  # ]
     692                 :        234 :             ++orig;
     693                 :            :         }
     694                 :            : 
     695 [ +  - ][ +  - ]:        177 :         TEST_AND_EXPLAIN(*orig == *filt &&
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     696                 :            :                          orig.get_weight() == filt.get_weight(),
     697                 :            :                          "Mismatch in items " << *orig << " vs. " << *filt
     698                 :            :                          << " after filtering");
     699                 :            :     }
     700                 :            : 
     701 [ +  - ][ +  + ]:         21 :     while (orig != myeset_orig.end() && !myfunctor(*orig)) {
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
         [ +  - ][ +  +  
             #  #  #  # ]
     702                 :         14 :         ++orig;
     703                 :            :     }
     704                 :            : 
     705 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(orig, myeset_orig.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     706 [ +  - ][ -  + ]:          7 :     TEST_AND_EXPLAIN(filt == myeset.end(),
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     707                 :            :                      "Extra items in the filtered eset.");
     708                 :          7 :     return true;
     709                 :            : }
     710                 :            : 
     711                 :          7 : DEFINE_TESTCASE(expanddeciderfilterprefix2, backend) {
     712 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     713 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     714                 :            : 
     715         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     716 [ +  - ][ -  + ]:          7 :     TEST(mymset.size() >= 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     717                 :            : 
     718         [ +  - ]:         14 :     Xapian::RSet myrset;
     719         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     720 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     721 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     722                 :            : 
     723         [ +  - ]:         14 :     Xapian::ESet myeset_orig = enquire.get_eset(1000, myrset);
     724                 :          7 :     unsigned int neweset_size = 0;
     725                 :            : 
     726                 :            :     // Choose the first char in the first term as prefix.
     727         [ +  - ]:         14 :     Xapian::ESetIterator j = myeset_orig.begin();
     728 [ +  - ][ -  + ]:          7 :     TEST(myeset_orig.size() >= 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     729 [ +  - ][ +  - ]:         14 :     string prefix(*j, 0, 1);
     730         [ +  - ]:         14 :     Xapian::ExpandDeciderFilterPrefix myfunctor(prefix);
     731                 :            : 
     732 [ +  - ][ +  + ]:        432 :     for ( ; j != myeset_orig.end(); ++j) {
     733 [ +  - ][ +  - ]:        425 :         if (myfunctor(*j)) neweset_size++;
                 [ +  + ]
     734                 :            :     }
     735         [ +  - ]:         14 :     Xapian::ESet myeset = enquire.get_eset(neweset_size, myrset, &myfunctor);
     736                 :            : 
     737         [ +  - ]:         14 :     Xapian::ESetIterator orig = myeset_orig.begin();
     738         [ +  - ]:         14 :     Xapian::ESetIterator filt = myeset.begin();
     739 [ +  - ][ +  - ]:         47 :     for (; orig != myeset_orig.end() && filt != myeset.end(); ++orig, ++filt) {
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
           [ +  +  #  #  
                   #  # ]
     740                 :            :         // skip over items that shouldn't be in myeset
     741 [ +  - ][ +  - ]:        384 :         while (orig != myeset_orig.end() && !myfunctor(*orig)) {
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
         [ +  - ][ +  +  
             #  #  #  # ]
     742                 :        344 :             ++orig;
     743                 :            :         }
     744                 :            : 
     745 [ +  - ][ +  - ]:         40 :         TEST_AND_EXPLAIN(*orig == *filt &&
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     746                 :            :             orig.get_weight() == filt.get_weight(),
     747                 :            :             "Mismatch in items " << *orig << " vs. " << *filt
     748                 :            :             << " after filtering");
     749                 :            :     }
     750                 :            : 
     751 [ +  - ][ +  + ]:         48 :     while (orig != myeset_orig.end() && !myfunctor(*orig)) {
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
         [ +  - ][ +  +  
             #  #  #  # ]
     752                 :         41 :         ++orig;
     753                 :            :     }
     754                 :            : 
     755 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(orig, myeset_orig.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     756 [ +  - ][ -  + ]:          7 :     TEST_AND_EXPLAIN(filt == myeset.end(),
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     757                 :            :                      "Extra items in the filtered eset.");
     758                 :            : 
     759                 :          7 :     return true;
     760                 :            : }
     761                 :            : 
     762                 :            : // tests the percent cutoff option
     763                 :          7 : DEFINE_TESTCASE(pctcutoff1, backend) {
     764 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     765                 :            :     enquire.set_query(query(Xapian::Query::OP_OR,
     766 [ +  - ][ +  - ]:          7 :                             "this", "line", "paragraph", "rubbish"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     767         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 100);
     768                 :            : 
     769         [ +  - ]:          7 :     if (verbose) {
     770         [ +  - ]:          7 :         tout << "Original mset pcts:";
     771         [ +  - ]:          7 :         print_mset_percentages(mymset1);
     772         [ +  - ]:          7 :         tout << "\n";
     773                 :            :     }
     774                 :            : 
     775                 :          7 :     unsigned int num_items = 0;
     776                 :          7 :     int my_pct = 100;
     777                 :          7 :     int changes = 0;
     778         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset1.begin();
     779                 :          7 :     int c = 0;
     780 [ +  - ][ +  - ]:         28 :     for ( ; i != mymset1.end(); ++i, ++c) {
     781         [ +  - ]:         28 :         int new_pct = mymset1.convert_to_percent(i);
     782         [ +  - ]:         28 :         if (new_pct != my_pct) {
     783                 :         28 :             changes++;
     784         [ +  + ]:         28 :             if (changes > 3) break;
     785                 :         21 :             num_items = c;
     786                 :         21 :             my_pct = new_pct;
     787                 :            :         }
     788                 :            :     }
     789                 :            : 
     790 [ -  + ][ #  # ]:          7 :     TEST_AND_EXPLAIN(changes > 3, "MSet not varied enough to test");
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     791         [ +  - ]:          7 :     if (verbose) {
     792 [ +  - ][ +  - ]:          7 :         tout << "Cutoff percent: " << my_pct << "\n";
                 [ +  - ]
     793                 :            :     }
     794                 :            : 
     795         [ +  - ]:          7 :     enquire.set_cutoff(my_pct);
     796         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 100);
     797                 :            : 
     798         [ +  - ]:          7 :     if (verbose) {
     799         [ +  - ]:          7 :         tout << "Percentages after cutoff:";
     800         [ +  - ]:          7 :         print_mset_percentages(mymset2);
     801         [ +  - ]:          7 :         tout << "\n";
     802                 :            :     }
     803                 :            : 
     804 [ +  - ][ -  + ]:          7 :     TEST_AND_EXPLAIN(mymset2.size() >= num_items,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     805                 :            :                      "Match with % cutoff lost too many items");
     806                 :            : 
     807 [ +  - ][ +  - ]:          7 :     TEST_AND_EXPLAIN(mymset2.size() == num_items ||
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     808                 :            :                      (mymset2.convert_to_percent(mymset2[num_items]) == my_pct &&
     809                 :            :                       mymset2.convert_to_percent(mymset2.back()) == my_pct),
     810                 :            :                      "Match with % cutoff returned too many items");
     811                 :            : 
     812                 :          7 :     return true;
     813                 :            : }
     814                 :            : 
     815                 :            : // Tests the percent cutoff option combined with collapsing
     816                 :          7 : DEFINE_TESTCASE(pctcutoff2, backend) {
     817 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     818 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     819 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query(Xapian::Query::OP_AND_NOT, Xapian::Query("this"), Xapian::Query("banana")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     820         [ +  - ]:         14 :     Xapian::MSet mset = enquire.get_mset(0, 100);
     821                 :            : 
     822         [ +  - ]:          7 :     if (verbose) {
     823         [ +  - ]:          7 :         tout << "Original mset pcts:";
     824         [ +  - ]:          7 :         print_mset_percentages(mset);
     825         [ +  - ]:          7 :         tout << "\n";
     826                 :            :     }
     827                 :            : 
     828 [ +  - ][ -  + ]:          7 :     TEST(mset.size() >= 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     829 [ +  - ][ +  - ]:          7 :     TEST(mset[0].get_percent() - mset[1].get_percent() >= 2);
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     830                 :            : 
     831 [ +  - ][ +  - ]:          7 :     int cutoff = mset[0].get_percent() + mset[1].get_percent();
         [ +  - ][ +  - ]
     832                 :          7 :     cutoff /= 2;
     833                 :            : 
     834         [ +  - ]:          7 :     enquire.set_cutoff(cutoff);
     835         [ +  - ]:          7 :     enquire.set_collapse_key(1234); // Value which is always empty.
     836                 :            : 
     837         [ +  - ]:         14 :     Xapian::MSet mset2 = enquire.get_mset(0, 1);
     838 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset2.size(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     839 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mset2.get_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     840 [ +  - ][ -  + ]:          7 :     TEST_REL(mset2.get_uncollapsed_matches_lower_bound(),>=,1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     841 [ +  - ][ +  - ]:          7 :     TEST_REL(mset2.get_uncollapsed_matches_lower_bound(),<=,mset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     842 [ +  - ][ +  - ]:          7 :     TEST_REL(mset2.get_uncollapsed_matches_upper_bound(),>=,mset.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     843 [ +  - ][ +  - ]:          7 :     TEST_REL(mset2.get_uncollapsed_matches_lower_bound(),<=,mset2.get_uncollapsed_matches_estimated());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     844 [ +  - ][ +  - ]:          7 :     TEST_REL(mset2.get_uncollapsed_matches_upper_bound(),>=,mset2.get_uncollapsed_matches_estimated());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     845                 :            : 
     846                 :          7 :     return true;
     847                 :            : }
     848                 :            : 
     849                 :            : // Test that the percent cutoff option returns all the answers it should.
     850                 :          7 : DEFINE_TESTCASE(pctcutoff3, backend) {
     851 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     852 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     853         [ +  - ]:         14 :     Xapian::MSet mset1 = enquire.get_mset(0, 10);
     854                 :            : 
     855         [ +  - ]:          7 :     if (verbose) {
     856         [ +  - ]:          7 :         tout << "Original mset pcts:";
     857         [ +  - ]:          7 :         print_mset_percentages(mset1);
     858         [ +  - ]:          7 :         tout << "\n";
     859                 :            :     }
     860                 :            : 
     861                 :          7 :     int percent = 100;
     862 [ +  - ][ +  - ]:         49 :     for (Xapian::MSetIterator i = mset1.begin(); i != mset1.end(); ++i) {
                 [ +  + ]
     863         [ +  - ]:         42 :         int new_percent = mset1.convert_to_percent(i);
     864         [ +  + ]:         42 :         if (new_percent != percent) {
     865 [ +  - ][ +  - ]:         21 :             tout.str(string());
     866 [ +  - ][ +  - ]:         21 :             tout << "Testing " << percent << "% cutoff" << endl;
         [ +  - ][ +  - ]
     867         [ +  - ]:         21 :             enquire.set_cutoff(percent);
     868         [ +  - ]:         21 :             Xapian::MSet mset2 = enquire.get_mset(0, 10);
     869 [ +  - ][ +  - ]:         21 :             TEST_EQUAL(mset2.back().get_percent(), percent);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     870 [ +  - ][ +  - ]:         21 :             TEST_EQUAL(mset2.size(), i.get_rank());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     871                 :         21 :             percent = new_percent;
     872                 :            :         }
     873                 :          7 :     }
     874                 :            : 
     875                 :          7 :     return true;
     876                 :            : }
     877                 :            : 
     878                 :            : // tests the cutoff option
     879                 :          7 : DEFINE_TESTCASE(cutoff1, backend) {
     880 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     881                 :            :     enquire.set_query(query(Xapian::Query::OP_OR,
     882 [ +  - ][ +  - ]:          7 :                             "this", "line", "paragraph", "rubbish"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     883         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 100);
     884                 :            : 
     885         [ +  - ]:          7 :     if (verbose) {
     886         [ +  - ]:          7 :         tout << "Original mset weights:";
     887         [ +  - ]:          7 :         print_mset_weights(mymset1);
     888         [ +  - ]:          7 :         tout << "\n";
     889                 :            :     }
     890                 :            : 
     891                 :          7 :     unsigned int num_items = 0;
     892                 :          7 :     double my_wt = -100;
     893                 :          7 :     int changes = 0;
     894         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset1.begin();
     895                 :          7 :     int c = 0;
     896 [ +  - ][ +  - ]:         28 :     for ( ; i != mymset1.end(); ++i, ++c) {
     897         [ +  - ]:         28 :         double new_wt = i.get_weight();
     898         [ +  - ]:         28 :         if (new_wt != my_wt) {
     899                 :         28 :             changes++;
     900         [ +  + ]:         28 :             if (changes > 3) break;
     901                 :         21 :             num_items = c;
     902                 :         21 :             my_wt = new_wt;
     903                 :            :         }
     904                 :            :     }
     905                 :            : 
     906 [ -  + ][ #  # ]:          7 :     TEST_AND_EXPLAIN(changes > 3, "MSet not varied enough to test");
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     907         [ +  - ]:          7 :     if (verbose) {
     908 [ +  - ][ +  - ]:          7 :         tout << "Cutoff weight: " << my_wt << "\n";
                 [ +  - ]
     909                 :            :     }
     910                 :            : 
     911         [ +  - ]:          7 :     enquire.set_cutoff(0, my_wt);
     912         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 100);
     913                 :            : 
     914         [ +  - ]:          7 :     if (verbose) {
     915         [ +  - ]:          7 :         tout << "Weights after cutoff:";
     916         [ +  - ]:          7 :         print_mset_weights(mymset2);
     917         [ +  - ]:          7 :         tout << "\n";
     918                 :            :     }
     919                 :            : 
     920 [ +  - ][ -  + ]:          7 :     TEST_AND_EXPLAIN(mymset2.size() >= num_items,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     921                 :            :                      "Match with cutoff lost too many items");
     922                 :            : 
     923 [ +  - ][ +  - ]:          7 :     TEST_AND_EXPLAIN(mymset2.size() == num_items ||
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     924                 :            :                      (mymset2[num_items].get_weight() == my_wt &&
     925                 :            :                       mymset2.back().get_weight() == my_wt),
     926                 :            :                      "Match with cutoff returned too many items");
     927                 :            : 
     928                 :          7 :     return true;
     929                 :            : }
     930                 :            : 
     931                 :            : // tests the allow query terms expand option
     932                 :          7 : DEFINE_TESTCASE(allowqterms1, backend) {
     933 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     934         [ +  - ]:         14 :     string term = "paragraph";
     935 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query(term));
     936                 :            : 
     937         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     938 [ +  - ][ -  + ]:          7 :     TEST(mymset.size() >= 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     939                 :            : 
     940         [ +  - ]:         14 :     Xapian::RSet myrset;
     941         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     942 [ +  - ][ +  - ]:          7 :     myrset.add_document(*i);
     943 [ +  - ][ +  - ]:          7 :     myrset.add_document(*(++i));
     944                 :            : 
     945         [ +  - ]:         14 :     Xapian::ESet myeset = enquire.get_eset(1000, myrset);
     946         [ +  - ]:         14 :     Xapian::ESetIterator j = myeset.begin();
     947 [ +  - ][ +  + ]:        218 :     for ( ; j != myeset.end(); ++j) {
     948 [ +  - ][ -  + ]:        211 :         TEST_NOT_EQUAL(*j, term);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     949                 :            :     }
     950                 :            : 
     951         [ +  - ]:         14 :     Xapian::ESet myeset2 = enquire.get_eset(1000, myrset, Xapian::Enquire::INCLUDE_QUERY_TERMS);
     952 [ +  - ][ +  - ]:          7 :     j = myeset2.begin();
     953 [ +  - ][ +  - ]:        151 :     for ( ; j != myeset2.end(); ++j) {
     954 [ +  - ][ +  + ]:        151 :         if (*j == term) break;
     955                 :            :     }
     956 [ +  - ][ -  + ]:          7 :     TEST(j != myeset2.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     957                 :          7 :     return true;
     958                 :            : }
     959                 :            : 
     960                 :            : // tests that the MSet max_attained works
     961                 :          7 : DEFINE_TESTCASE(maxattain1, backend) {
     962 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     963 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
     964         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 100);
     965                 :            : 
     966                 :          7 :     double mymax = 0;
     967         [ +  - ]:         14 :     Xapian::MSetIterator i = mymset.begin();
     968 [ +  - ][ +  + ]:         49 :     for ( ; i != mymset.end(); ++i) {
     969 [ +  - ][ +  + ]:         42 :         if (i.get_weight() > mymax) mymax = i.get_weight();
                 [ +  - ]
     970                 :            :     }
     971 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymax, mymset.get_max_attained());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     972                 :            : 
     973                 :          7 :     return true;
     974                 :            : }
     975                 :            : 
     976                 :            : // tests a reversed boolean query
     977                 :          7 : DEFINE_TESTCASE(reversebool1, backend) {
     978 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
     979 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
     980         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     981                 :            : 
     982         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 100);
     983 [ +  - ][ -  + ]:          7 :     TEST_AND_EXPLAIN(mymset1.size() > 1,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     984                 :            :                      "Mset was too small to test properly");
     985                 :            : 
     986         [ +  - ]:          7 :     enquire.set_docid_order(Xapian::Enquire::ASCENDING);
     987         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 100);
     988         [ +  - ]:          7 :     enquire.set_docid_order(Xapian::Enquire::DESCENDING);
     989         [ +  - ]:         14 :     Xapian::MSet mymset3 = enquire.get_mset(0, 100);
     990                 :            : 
     991                 :            :     // mymset1 and mymset2 should be identical
     992 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.size(), mymset2.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     993                 :            : 
     994                 :            :     {
     995         [ +  - ]:          7 :         Xapian::MSetIterator i = mymset1.begin();
     996         [ +  - ]:         14 :         Xapian::MSetIterator j = mymset2.begin();
     997 [ +  - ][ +  - ]:         49 :         for ( ; i != mymset1.end(); ++i, j++) {
                 [ +  + ]
     998 [ +  - ][ -  + ]:         42 :             TEST(j != mymset2.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     999                 :            :             // if this fails, then setting match_sort_forward=true was not
    1000                 :            :             // the same as the default.
    1001 [ +  - ][ +  - ]:         42 :             TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1002                 :            :         }
    1003 [ +  - ][ -  + ]:         14 :         TEST(j == mymset2.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1004                 :            :     }
    1005                 :            : 
    1006                 :            :     // mymset1 and mymset3 should be same but reversed
    1007 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.size(), mymset3.size());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1008                 :            : 
    1009                 :            :     {
    1010         [ +  - ]:          7 :         Xapian::MSetIterator i = mymset1.begin();
    1011         [ +  - ]:         14 :         Xapian::MSetIterator j = mymset3.end();
    1012 [ +  - ][ +  + ]:         49 :         for ( ; i != mymset1.end(); ++i) {
    1013                 :         42 :             --j;
    1014                 :            :             // if this fails, then setting match_sort_forward=false didn't
    1015                 :            :             // reverse the results.
    1016 [ +  - ][ +  - ]:         42 :             TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1017                 :          7 :         }
    1018                 :            :     }
    1019                 :            : 
    1020                 :          7 :     return true;
    1021                 :            : }
    1022                 :            : 
    1023                 :            : // tests a reversed boolean query, where the full mset isn't returned
    1024                 :          7 : DEFINE_TESTCASE(reversebool2, backend) {
    1025 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1026 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
    1027         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
    1028                 :            : 
    1029         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 100);
    1030                 :            : 
    1031 [ +  - ][ -  + ]:          7 :     TEST_AND_EXPLAIN(mymset1.size() > 1,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1032                 :            :                      "Mset was too small to test properly");
    1033                 :            : 
    1034         [ +  - ]:          7 :     enquire.set_docid_order(Xapian::Enquire::ASCENDING);
    1035         [ +  - ]:          7 :     Xapian::doccount msize = mymset1.size() / 2;
    1036         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, msize);
    1037         [ +  - ]:          7 :     enquire.set_docid_order(Xapian::Enquire::DESCENDING);
    1038         [ +  - ]:         14 :     Xapian::MSet mymset3 = enquire.get_mset(0, msize);
    1039                 :            : 
    1040                 :            :     // mymset2 should be first msize items of mymset1
    1041 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(msize, mymset2.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1042                 :            :     {
    1043         [ +  - ]:          7 :         Xapian::MSetIterator i = mymset1.begin();
    1044         [ +  - ]:         14 :         Xapian::MSetIterator j = mymset2.begin();
    1045 [ +  - ][ +  + ]:         28 :         for ( ; j != mymset2.end(); ++i, ++j) {
    1046 [ +  - ][ -  + ]:         21 :             TEST(i != mymset1.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1047                 :            :             // if this fails, then setting match_sort_forward=true was not
    1048                 :            :             // the same as the default.
    1049 [ +  - ][ +  - ]:         21 :             TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1050                 :            :         }
    1051                 :            :         // mymset1 should be larger.
    1052 [ +  - ][ -  + ]:         14 :         TEST(i != mymset1.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1053                 :            :     }
    1054                 :            : 
    1055                 :            :     // mymset3 should be last msize items of mymset1, in reverse order
    1056 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(msize, mymset3.size());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1057                 :            :     {
    1058         [ +  - ]:          7 :         Xapian::MSetIterator i = mymset1.end();
    1059         [ +  - ]:         14 :         Xapian::MSetIterator j;
    1060 [ +  - ][ +  - ]:         28 :         for (j = mymset3.begin(); j != mymset3.end(); ++j) {
         [ +  - ][ +  + ]
    1061                 :            :             // if this fails, then setting match_sort_forward=false didn't
    1062                 :            :             // reverse the results.
    1063                 :         21 :             --i;
    1064 [ +  - ][ +  - ]:         21 :             TEST_EQUAL(*i, *j);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1065                 :          7 :         }
    1066                 :            :     }
    1067                 :            : 
    1068                 :          7 :     return true;
    1069                 :            : }
    1070                 :            : 
    1071                 :            : // tests that get_matching_terms() returns the terms in the right order
    1072                 :          7 : DEFINE_TESTCASE(getmterms1, backend) {
    1073                 :          7 :     list<string> answers_list;
    1074 [ +  - ][ +  - ]:          7 :     answers_list.push_back("one");
    1075 [ +  - ][ +  - ]:          7 :     answers_list.push_back("two");
    1076 [ +  - ][ +  - ]:          7 :     answers_list.push_back("three");
    1077 [ +  - ][ +  - ]:          7 :     answers_list.push_back("four");
    1078                 :            : 
    1079 [ +  - ][ +  - ]:         14 :     Xapian::Database mydb(get_database("apitest_termorder"));
    1080         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1081                 :            : 
    1082                 :            :     Xapian::Query myquery(Xapian::Query::OP_OR,
    1083                 :            :             Xapian::Query(Xapian::Query::OP_AND,
    1084                 :            :                     Xapian::Query("one", 1, 1),
    1085                 :            :                     Xapian::Query("three", 1, 3)),
    1086                 :            :             Xapian::Query(Xapian::Query::OP_OR,
    1087                 :            :                     Xapian::Query("four", 1, 4),
    1088 [ +  - ][ +  - ]:         14 :                     Xapian::Query("two", 1, 2)));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1089                 :            : 
    1090         [ +  - ]:          7 :     enquire.set_query(myquery);
    1091                 :            : 
    1092         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
    1093                 :            : 
    1094 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1095                 :            :     list<string> list(enquire.get_matching_terms_begin(mymset.begin()),
    1096 [ +  - ][ +  - ]:         14 :                           enquire.get_matching_terms_end(mymset.begin()));
         [ +  - ][ +  - ]
    1097 [ -  + ][ #  # ]:          7 :     TEST(list == answers_list);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1098                 :            : 
    1099                 :          7 :     return true;
    1100                 :            : }
    1101                 :            : 
    1102                 :            : // tests that get_matching_terms() returns the terms only once
    1103                 :          7 : DEFINE_TESTCASE(getmterms2, backend) {
    1104                 :          7 :     list<string> answers_list;
    1105 [ +  - ][ +  - ]:          7 :     answers_list.push_back("one");
    1106 [ +  - ][ +  - ]:          7 :     answers_list.push_back("two");
    1107 [ +  - ][ +  - ]:          7 :     answers_list.push_back("three");
    1108                 :            : 
    1109 [ +  - ][ +  - ]:         14 :     Xapian::Database mydb(get_database("apitest_termorder"));
    1110         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1111                 :            : 
    1112                 :            :     Xapian::Query myquery(Xapian::Query::OP_OR,
    1113                 :            :             Xapian::Query(Xapian::Query::OP_AND,
    1114                 :            :                     Xapian::Query("one", 1, 1),
    1115                 :            :                     Xapian::Query("three", 1, 3)),
    1116                 :            :             Xapian::Query(Xapian::Query::OP_OR,
    1117                 :            :                     Xapian::Query("one", 1, 4),
    1118 [ +  - ][ +  - ]:         14 :                     Xapian::Query("two", 1, 2)));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1119                 :            : 
    1120         [ +  - ]:          7 :     enquire.set_query(myquery);
    1121                 :            : 
    1122         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
    1123                 :            : 
    1124 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1125                 :            :     list<string> list(enquire.get_matching_terms_begin(mymset.begin()),
    1126 [ +  - ][ +  - ]:         14 :                           enquire.get_matching_terms_end(mymset.begin()));
         [ +  - ][ +  - ]
    1127 [ -  + ][ #  # ]:          7 :     TEST(list == answers_list);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1128                 :            : 
    1129                 :          7 :     return true;
    1130                 :            : }
    1131                 :            : 
    1132                 :            : // test that running a query twice returns the same results
    1133                 :          7 : DEFINE_TESTCASE(repeatquery1, backend) {
    1134 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1135 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
    1136                 :            : 
    1137 [ +  - ][ +  - ]:          7 :     enquire.set_query(query(Xapian::Query::OP_OR, "this", "word"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1138                 :            : 
    1139         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 10);
    1140         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 10);
    1141 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1, mymset2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1142                 :            : 
    1143                 :          7 :     return true;
    1144                 :            : }
    1145                 :            : 
    1146                 :            : // test that prefetching documents works (at least, gives same results)
    1147                 :          7 : DEFINE_TESTCASE(fetchdocs1, backend) {
    1148 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1149 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("this"));
                 [ +  - ]
    1150                 :            : 
    1151 [ +  - ][ +  - ]:          7 :     enquire.set_query(query(Xapian::Query::OP_OR, "this", "word"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1152                 :            : 
    1153         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 10);
    1154         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 10);
    1155 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1, mymset2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1156 [ +  - ][ +  - ]:          7 :     mymset2.fetch(mymset2[0], mymset2[mymset2.size() - 1]);
         [ +  - ][ +  - ]
    1157 [ +  - ][ +  - ]:          7 :     mymset2.fetch(mymset2.begin(), mymset2.end());
                 [ +  - ]
    1158 [ +  - ][ +  - ]:          7 :     mymset2.fetch(mymset2.begin());
    1159         [ +  - ]:          7 :     mymset2.fetch();
    1160                 :            : 
    1161         [ +  - ]:         14 :     Xapian::MSetIterator it1 = mymset1.begin();
    1162         [ +  - ]:         14 :     Xapian::MSetIterator it2 = mymset2.begin();
    1163                 :            : 
    1164 [ +  - ][ +  + ]:         49 :     while (it1 != mymset1.end() && it2 != mymset2.end()) {
         [ +  - ][ +  - ]
         [ +  + ][ +  - ]
           [ +  +  #  #  
                   #  # ]
    1165 [ +  - ][ +  - ]:         42 :         TEST_EQUAL(it1.get_document().get_data(),
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1166                 :            :                    it2.get_document().get_data());
    1167 [ +  - ][ +  - ]:         42 :         TEST_NOT_EQUAL(it1.get_document().get_data(), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1168 [ +  - ][ +  - ]:         42 :         TEST_NOT_EQUAL(it2.get_document().get_data(), "");
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1169         [ +  - ]:         42 :         it1++;
    1170         [ +  - ]:         42 :         it2++;
    1171                 :            :     }
    1172 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(it1, mymset1.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1173 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(it1, mymset2.end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1174                 :            : 
    1175                 :          7 :     return true;
    1176                 :            : }
    1177                 :            : 
    1178                 :            : // test that searching for a term not in the database fails nicely
    1179                 :          7 : DEFINE_TESTCASE(absentterm1, backend) {
    1180 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1181         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
    1182 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query("frink"));
                 [ +  - ]
    1183                 :            : 
    1184         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
    1185         [ +  - ]:          7 :     mset_expect_order(mymset);
    1186                 :            : 
    1187                 :          7 :     return true;
    1188                 :            : }
    1189                 :            : 
    1190                 :            : // as absentterm1, but setting query from a vector of terms
    1191                 :          7 : DEFINE_TESTCASE(absentterm2, backend) {
    1192 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1193                 :         14 :     vector<string> terms;
    1194 [ +  - ][ +  - ]:          7 :     terms.push_back("frink");
    1195                 :            : 
    1196         [ +  - ]:         14 :     Xapian::Query query(Xapian::Query::OP_OR, terms.begin(), terms.end());
    1197         [ +  - ]:          7 :     enquire.set_query(query);
    1198                 :            : 
    1199         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
    1200         [ +  - ]:          7 :     mset_expect_order(mymset);
    1201                 :            : 
    1202                 :          7 :     return true;
    1203                 :            : }
    1204                 :            : 
    1205                 :            : // test that rsets do sensible things
    1206                 :          7 : DEFINE_TESTCASE(rset1, backend) {
    1207 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_rset"));
    1208         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1209 [ +  - ][ +  - ]:         14 :     Xapian::Query myquery = query(Xapian::Query::OP_OR, "giraffe", "tiger");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1210         [ +  - ]:          7 :     enquire.set_query(myquery);
    1211                 :            : 
    1212         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 10);
    1213                 :            : 
    1214         [ +  - ]:         14 :     Xapian::RSet myrset;
    1215         [ +  - ]:          7 :     myrset.add_document(1);
    1216                 :            : 
    1217         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 10, &myrset);
    1218                 :            : 
    1219                 :            :     // We should have the same documents turn up, but 1 and 3 should
    1220                 :            :     // have higher weights with the RSet.
    1221 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset1, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1222 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset2, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1223                 :            : 
    1224                 :          7 :     return true;
    1225                 :            : }
    1226                 :            : 
    1227                 :            : // test that rsets do more sensible things
    1228                 :          7 : DEFINE_TESTCASE(rset2, backend) {
    1229 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_rset"));
    1230         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1231 [ +  - ][ +  - ]:         14 :     Xapian::Query myquery = query(Xapian::Query::OP_OR, "cuddly", "people");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1232         [ +  - ]:          7 :     enquire.set_query(myquery);
    1233                 :            : 
    1234         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 10);
    1235                 :            : 
    1236         [ +  - ]:         14 :     Xapian::RSet myrset;
    1237         [ +  - ]:          7 :     myrset.add_document(2);
    1238                 :            : 
    1239         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 10, &myrset);
    1240                 :            : 
    1241         [ +  - ]:          7 :     mset_expect_order(mymset1, 1, 2);
    1242         [ +  - ]:          7 :     mset_expect_order(mymset2, 2, 1);
    1243                 :            : 
    1244                 :          7 :     return true;
    1245                 :            : }
    1246                 :            : 
    1247                 :            : // test that rsets behave correctly with multiDBs
    1248                 :          6 : DEFINE_TESTCASE(rsetmultidb1, backend && !multi) {
    1249 [ +  - ][ +  - ]:          6 :     Xapian::Database mydb1(get_database("apitest_rset", "apitest_simpledata2"));
                 [ +  - ]
    1250 [ +  - ][ +  - ]:         12 :     Xapian::Database mydb2(get_database("apitest_rset"));
    1251 [ +  - ][ +  - ]:          6 :     mydb2.add_database(get_database("apitest_simpledata2"));
                 [ +  - ]
    1252                 :            : 
    1253         [ +  - ]:         12 :     Xapian::Enquire enquire1(mydb1);
    1254         [ +  - ]:         12 :     Xapian::Enquire enquire2(mydb2);
    1255                 :            : 
    1256 [ +  - ][ +  - ]:         12 :     Xapian::Query myquery = query(Xapian::Query::OP_OR, "cuddly", "multiple");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1257                 :            : 
    1258         [ +  - ]:          6 :     enquire1.set_query(myquery);
    1259         [ +  - ]:          6 :     enquire2.set_query(myquery);
    1260                 :            : 
    1261         [ +  - ]:         12 :     Xapian::RSet myrset1;
    1262         [ +  - ]:         12 :     Xapian::RSet myrset2;
    1263         [ +  - ]:          6 :     myrset1.add_document(4);
    1264         [ +  - ]:          6 :     myrset2.add_document(2);
    1265                 :            : 
    1266         [ +  - ]:         12 :     Xapian::MSet mymset1a = enquire1.get_mset(0, 10);
    1267         [ +  - ]:         12 :     Xapian::MSet mymset1b = enquire1.get_mset(0, 10, &myrset1);
    1268         [ +  - ]:         12 :     Xapian::MSet mymset2a = enquire2.get_mset(0, 10);
    1269         [ +  - ]:         12 :     Xapian::MSet mymset2b = enquire2.get_mset(0, 10, &myrset2);
    1270                 :            : 
    1271         [ +  - ]:          6 :     mset_expect_order(mymset1a, 1, 4);
    1272         [ +  - ]:          6 :     mset_expect_order(mymset1b, 4, 1);
    1273         [ +  - ]:          6 :     mset_expect_order(mymset2a, 1, 2);
    1274         [ +  - ]:          6 :     mset_expect_order(mymset2b, 2, 1);
    1275                 :            : 
    1276 [ +  - ][ -  + ]:          6 :     TEST(mset_range_is_same_weights(mymset1a, 0, mymset2a, 0, 2));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1277 [ +  - ][ -  + ]:          6 :     TEST(mset_range_is_same_weights(mymset1b, 0, mymset2b, 0, 2));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1278 [ +  - ][ -  + ]:          6 :     TEST_NOT_EQUAL(mymset1a, mymset1b);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1279 [ +  - ][ -  + ]:          6 :     TEST_NOT_EQUAL(mymset2a, mymset2b);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1280                 :            : 
    1281                 :          6 :     return true;
    1282                 :            : }
    1283                 :            : 
    1284                 :            : // regression tests - used to cause assertion in stats.h to fail
    1285                 :            : // Doesn't actually fail for multi but it doesn't make sense to run there.
    1286                 :          6 : DEFINE_TESTCASE(rsetmultidb3, backend && !multi) {
    1287 [ +  - ][ +  - ]:          6 :     Xapian::Enquire enquire(get_database("apitest_simpledata2"));
                 [ +  - ]
    1288 [ +  - ][ +  - ]:          6 :     enquire.set_query(query(Xapian::Query::OP_OR, "cuddly", "people"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1289         [ +  - ]:          6 :     Xapian::MSet mset = enquire.get_mset(0, 10); // used to fail assertion
    1290                 :          6 :     return true;
    1291                 :            : }
    1292                 :            : 
    1293                 :            : /// Simple test of the elite set operator.
    1294                 :          7 : DEFINE_TESTCASE(eliteset1, backend) {
    1295 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_simpledata"));
    1296         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1297                 :            : 
    1298 [ +  - ][ +  - ]:         14 :     Xapian::Query myquery1 = query(Xapian::Query::OP_OR, "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1299                 :            : 
    1300                 :            :     Xapian::Query myquery2 = query(Xapian::Query::OP_ELITE_SET, 1,
    1301 [ +  - ][ +  - ]:         14 :                                    "simple", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1302                 :            : 
    1303         [ +  - ]:          7 :     enquire.set_query(myquery1, 2); // So the query lengths are the same.
    1304         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 10);
    1305                 :            : 
    1306         [ +  - ]:          7 :     enquire.set_query(myquery2);
    1307         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 10);
    1308                 :            : 
    1309 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1, mymset2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1310                 :          7 :     return true;
    1311                 :            : }
    1312                 :            : 
    1313                 :            : /// Test that the elite set operator works if the set contains
    1314                 :            : /// sub-expressions (regression test)
    1315                 :          7 : DEFINE_TESTCASE(eliteset2, backend) {
    1316 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_simpledata"));
    1317         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1318                 :            : 
    1319 [ +  - ][ +  - ]:         14 :     Xapian::Query myquery1 = query(Xapian::Query::OP_AND, "word", "search");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1320                 :            : 
    1321                 :         14 :     vector<Xapian::Query> qs;
    1322 [ +  - ][ +  - ]:          7 :     qs.push_back(query("this"));
                 [ +  - ]
    1323 [ +  - ][ +  - ]:          7 :     qs.push_back(query(Xapian::Query::OP_AND, "word", "search"));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1324                 :            :     Xapian::Query myquery2(Xapian::Query::OP_ELITE_SET,
    1325         [ +  - ]:         14 :                            qs.begin(), qs.end(), 1);
    1326                 :            : 
    1327         [ +  - ]:          7 :     enquire.set_query(myquery1);
    1328         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 10);
    1329                 :            : 
    1330         [ +  - ]:          7 :     enquire.set_query(myquery2);
    1331         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 10);
    1332                 :            : 
    1333 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1, mymset2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1334                 :            :     // query lengths differ so mset weights not the same (with some weighting
    1335                 :            :     // parameters)
    1336                 :            :     // test_mset_order_equal(mymset1, mymset2);
    1337                 :            : 
    1338                 :          7 :     return true;
    1339                 :            : }
    1340                 :            : 
    1341                 :            : /// Test that elite set doesn't affect query results if we have fewer
    1342                 :            : /// terms than the threshold
    1343                 :          7 : DEFINE_TESTCASE(eliteset3, backend) {
    1344 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb1(get_database("apitest_simpledata"));
    1345         [ +  - ]:         14 :     Xapian::Enquire enquire1(mydb1);
    1346                 :            : 
    1347 [ +  - ][ +  - ]:         14 :     Xapian::Database mydb2(get_database("apitest_simpledata"));
    1348         [ +  - ]:         14 :     Xapian::Enquire enquire2(mydb2);
    1349                 :            : 
    1350                 :            :     // make a query
    1351 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
    1352                 :            : 
    1353 [ +  - ][ +  - ]:         14 :     string term1 = stemmer("word");
    1354 [ +  - ][ +  - ]:         14 :     string term2 = stemmer("rubbish");
    1355 [ +  - ][ +  - ]:         14 :     string term3 = stemmer("banana");
    1356                 :            : 
    1357                 :         14 :     vector<string> terms;
    1358         [ +  - ]:          7 :     terms.push_back(term1);
    1359         [ +  - ]:          7 :     terms.push_back(term2);
    1360         [ +  - ]:          7 :     terms.push_back(term3);
    1361                 :            : 
    1362         [ +  - ]:         14 :     Xapian::Query myquery1(Xapian::Query::OP_OR, terms.begin(), terms.end());
    1363         [ +  - ]:          7 :     enquire1.set_query(myquery1);
    1364                 :            : 
    1365         [ +  - ]:         14 :     Xapian::Query myquery2(Xapian::Query::OP_ELITE_SET, terms.begin(), terms.end(), 3);
    1366         [ +  - ]:          7 :     enquire2.set_query(myquery2);
    1367                 :            : 
    1368                 :            :     // retrieve the results
    1369         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire1.get_mset(0, 10);
    1370         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire2.get_mset(0, 10);
    1371                 :            : 
    1372 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_termfreq(term1),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1373                 :            :                mymset2.get_termfreq(term1));
    1374 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_termweight(term1),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1375                 :            :                mymset2.get_termweight(term1));
    1376 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_termfreq(term2),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1377                 :            :                mymset2.get_termfreq(term2));
    1378 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_termweight(term2),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1379                 :            :                mymset2.get_termweight(term2));
    1380 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_termfreq(term3),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1381                 :            :                mymset2.get_termfreq(term3));
    1382 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_termweight(term3),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1383                 :            :                mymset2.get_termweight(term3));
    1384                 :            : //    TEST_EQUAL(mymset1, mymset2);
    1385                 :            : 
    1386                 :          7 :     return true;
    1387                 :            : }
    1388                 :            : 
    1389                 :            : /// Test that elite set doesn't pick terms with 0 frequency
    1390                 :          7 : DEFINE_TESTCASE(eliteset4, backend) {
    1391 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb1(get_database("apitest_simpledata"));
    1392         [ +  - ]:         14 :     Xapian::Enquire enquire1(mydb1);
    1393                 :            : 
    1394 [ +  - ][ +  - ]:         14 :     Xapian::Database mydb2(get_database("apitest_simpledata"));
    1395         [ +  - ]:         14 :     Xapian::Enquire enquire2(mydb2);
    1396                 :            : 
    1397 [ +  - ][ +  - ]:         14 :     Xapian::Query myquery1 = query("rubbish");
    1398                 :            :     Xapian::Query myquery2 = query(Xapian::Query::OP_ELITE_SET, 1,
    1399 [ +  - ][ +  - ]:         14 :                                    "word", "rubbish", "fibble");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
    1400         [ +  - ]:          7 :     enquire1.set_query(myquery1);
    1401         [ +  - ]:          7 :     enquire2.set_query(myquery2);
    1402                 :            : 
    1403                 :            :     // retrieve the results
    1404         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire1.get_mset(0, 10);
    1405         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire2.get_mset(0, 10);
    1406                 :            : 
    1407 [ +  - ][ -  + ]:          7 :     TEST_NOT_EQUAL(mymset2.size(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1408 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1, mymset2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1409                 :            : 
    1410                 :          7 :     return true;
    1411                 :            : }
    1412                 :            : 
    1413                 :            : /// Regression test for problem with excess precision.
    1414                 :          7 : DEFINE_TESTCASE(eliteset5, backend) {
    1415 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb1(get_database("apitest_simpledata"));
    1416         [ +  - ]:         14 :     Xapian::Enquire enquire1(mydb1);
    1417                 :            : 
    1418                 :         14 :     vector<string> v;
    1419         [ +  + ]:         28 :     for (int i = 0; i != 3; ++i) {
    1420 [ +  - ][ +  - ]:         21 :         v.push_back("simpl");
    1421 [ +  - ][ +  - ]:         21 :         v.push_back("queri");
    1422                 :            : 
    1423 [ +  - ][ +  - ]:         21 :         v.push_back("rubbish");
    1424 [ +  - ][ +  - ]:         21 :         v.push_back("rubbish");
    1425 [ +  - ][ +  - ]:         21 :         v.push_back("rubbish");
    1426 [ +  - ][ +  - ]:         21 :         v.push_back("word");
    1427 [ +  - ][ +  - ]:         21 :         v.push_back("word");
    1428 [ +  - ][ +  - ]:         21 :         v.push_back("word");
    1429                 :            :     }
    1430                 :            : 
    1431         [ +  + ]:        168 :     for (Xapian::termcount n = 1; n != v.size(); ++n) {
    1432                 :            :         Xapian::Query myquery1 = Xapian::Query(Xapian::Query::OP_ELITE_SET,
    1433         [ +  - ]:        161 :                                                v.begin(), v.end(), n);
    1434         [ +  - ]:        322 :         myquery1 = Xapian::Query(Xapian::Query::OP_SCALE_WEIGHT,
    1435                 :            :                                  myquery1,
    1436         [ +  - ]:        161 :                                  0.004);
    1437                 :            : 
    1438         [ +  - ]:        161 :         enquire1.set_query(myquery1);
    1439                 :            :         // On architectures with excess precision (or, at least, on x86), the
    1440                 :            :         // following call used to result in a segfault (at least when n=1).
    1441         [ +  - ]:        161 :         enquire1.get_mset(0, 10);
    1442                 :        161 :     }
    1443                 :            : 
    1444                 :          7 :     return true;
    1445                 :            : }
    1446                 :            : 
    1447                 :            : /// Test that the termfreq returned by termlists is correct.
    1448                 :          7 : DEFINE_TESTCASE(termlisttermfreq1, backend) {
    1449 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_simpledata"));
    1450         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
    1451 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
    1452         [ +  - ]:         14 :     Xapian::RSet rset1;
    1453         [ +  - ]:         14 :     Xapian::RSet rset2;
    1454         [ +  - ]:          7 :     rset1.add_document(5);
    1455         [ +  - ]:          7 :     rset2.add_document(6);
    1456                 :            : 
    1457         [ +  - ]:         14 :     Xapian::ESet eset1 = enquire.get_eset(1000, rset1);
    1458         [ +  - ]:         14 :     Xapian::ESet eset2 = enquire.get_eset(1000, rset2);
    1459                 :            : 
    1460                 :            :     // search for weight of term 'another'
    1461 [ +  - ][ +  - ]:         14 :     string theterm = stemmer("another");
    1462                 :            : 
    1463                 :          7 :     double wt1 = 0;
    1464                 :          7 :     double wt2 = 0;
    1465                 :            :     {
    1466         [ +  - ]:          7 :         Xapian::ESetIterator i = eset1.begin();
    1467 [ +  - ][ +  - ]:         51 :         for ( ; i != eset1.end(); ++i) {
    1468 [ +  - ][ +  + ]:         51 :             if (*i == theterm) {
    1469         [ +  - ]:          7 :                 wt1 = i.get_weight();
    1470                 :          7 :                 break;
    1471                 :            :             }
    1472                 :          7 :         }
    1473                 :            :     }
    1474                 :            :     {
    1475         [ +  - ]:          7 :         Xapian::ESetIterator i = eset2.begin();
    1476 [ +  - ][ +  - ]:         81 :         for ( ; i != eset2.end(); ++i) {
    1477 [ +  - ][ +  + ]:         81 :             if (*i == theterm) {
    1478         [ +  - ]:          7 :                 wt2 = i.get_weight();
    1479                 :          7 :                 break;
    1480                 :            :             }
    1481                 :          7 :         }
    1482                 :            :     }
    1483                 :            : 
    1484 [ -  + ][ #  # ]:          7 :     TEST_NOT_EQUAL(wt1, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1485 [ -  + ][ #  # ]:          7 :     TEST_NOT_EQUAL(wt2, 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1486 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(wt1, wt2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1487                 :            : 
    1488                 :          7 :     return true;
    1489                 :            : }
    1490                 :            : 
    1491                 :            : /// Test the termfrequency and termweight info returned for query terms
    1492                 :          7 : DEFINE_TESTCASE(qterminfo1, backend) {
    1493 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb1(get_database("apitest_simpledata", "apitest_simpledata2"));
                 [ +  - ]
    1494         [ +  - ]:         14 :     Xapian::Enquire enquire1(mydb1);
    1495                 :            : 
    1496 [ +  - ][ +  - ]:         14 :     Xapian::Database mydb2(get_database("apitest_simpledata"));
    1497 [ +  - ][ +  - ]:          7 :     mydb2.add_database(get_database("apitest_simpledata2"));
                 [ +  - ]
    1498         [ +  - ]:         14 :     Xapian::Enquire enquire2(mydb2);
    1499                 :            : 
    1500                 :            :     // make a query
    1501 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
    1502                 :            : 
    1503 [ +  - ][ +  - ]:         14 :     string term1 = stemmer("word");
    1504 [ +  - ][ +  - ]:         14 :     string term2 = stemmer("inmemory");
    1505 [ +  - ][ +  - ]:         14 :     string term3 = stemmer("flibble");
    1506                 :            : 
    1507                 :            :     Xapian::Query myquery(Xapian::Query::OP_OR,
    1508                 :            :                     Xapian::Query(term1),
    1509                 :            :                     Xapian::Query(Xapian::Query::OP_OR,
    1510                 :            :                             Xapian::Query(term2),
    1511 [ +  - ][ +  - ]:         14 :                             Xapian::Query(term3)));
         [ +  - ][ +  - ]
                 [ +  - ]
    1512 [ +  - ][ +  - ]:          7 :     myquery = myquery &~ Xapian::Query("Boolean");
         [ +  - ][ +  - ]
    1513         [ +  - ]:          7 :     enquire1.set_query(myquery);
    1514         [ +  - ]:          7 :     enquire2.set_query(myquery);
    1515                 :            : 
    1516                 :            :     // retrieve the results
    1517         [ +  - ]:         14 :     Xapian::MSet mymset1a = enquire1.get_mset(0, 0);
    1518         [ +  - ]:         14 :     Xapian::MSet mymset2a = enquire2.get_mset(0, 0);
    1519                 :            : 
    1520 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(term1),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1521                 :            :                mymset2a.get_termfreq(term1));
    1522 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(term2),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1523                 :            :                mymset2a.get_termfreq(term2));
    1524 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(term3),
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1525                 :            :                mymset2a.get_termfreq(term3));
    1526                 :            : 
    1527 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(term1), 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1528 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(term2), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1529 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(term3), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1530                 :            : 
    1531 [ +  - ][ -  + ]:          7 :     TEST_NOT_EQUAL(mymset1a.get_termweight(term1), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1532 [ +  - ][ -  + ]:          7 :     TEST_NOT_EQUAL(mymset1a.get_termweight(term2), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1533                 :            :     // non-existent terms should have 0 weight.
    1534 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset1a.get_termweight(term3), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1535                 :            : 
    1536 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq(stemmer("banana")), 1);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1537 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termweight(stemmer("banana")), 0.0);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1538                 :            : 
    1539 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq("sponge"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1540 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termweight(stemmer("sponge")), 0.0);
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1541                 :            : 
    1542 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termfreq("Boolean"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1543 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1a.get_termweight("Boolean"), 0.0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1544                 :            : 
    1545                 :          7 :     return true;
    1546                 :            : }
    1547                 :            : 
    1548                 :            : /// Regression test for bug #37.
    1549                 :          7 : DEFINE_TESTCASE(qterminfo2, backend) {
    1550 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_simpledata"));
    1551         [ +  - ]:         14 :     Xapian::Enquire enquire(db);
    1552                 :            : 
    1553                 :            :     // make a query
    1554 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
    1555                 :            : 
    1556 [ +  - ][ +  - ]:         14 :     string term1 = stemmer("paragraph");
    1557 [ +  - ][ +  - ]:         14 :     string term2 = stemmer("another");
    1558                 :            : 
    1559 [ +  - ][ +  - ]:          7 :     enquire.set_query(Xapian::Query(term1));
    1560         [ +  - ]:         14 :     Xapian::MSet mset0 = enquire.get_mset(0, 10);
    1561                 :            : 
    1562 [ +  - ][ +  - ]:          7 :     TEST_NOT_EQUAL(mset0.get_termweight("paragraph"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1563                 :            : 
    1564                 :            :     Xapian::Query query(Xapian::Query::OP_AND_NOT, term1,
    1565 [ +  - ][ +  - ]:         14 :             Xapian::Query(Xapian::Query::OP_AND, term1, term2));
                 [ +  - ]
    1566         [ +  - ]:          7 :     enquire.set_query(query);
    1567                 :            : 
    1568                 :            :     // retrieve the results
    1569                 :            :     // Note: get_mset() used to throw "AssertionError" in debug builds
    1570         [ +  - ]:         14 :     Xapian::MSet mset = enquire.get_mset(0, 10);
    1571                 :            : 
    1572 [ +  - ][ +  - ]:          7 :     TEST_NOT_EQUAL(mset.get_termweight("paragraph"), 0);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1573                 :            : 
    1574                 :          7 :     return true;
    1575                 :            : }
    1576                 :            : 
    1577                 :            : // tests that when specifying that no items are to be returned, those
    1578                 :            : // statistics which should be the same are.
    1579                 :          7 : DEFINE_TESTCASE(msetzeroitems1, backend) {
    1580 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1581 [ +  - ][ +  - ]:          7 :     enquire.set_query(query("this"));
                 [ +  - ]
    1582         [ +  - ]:         14 :     Xapian::MSet mymset1 = enquire.get_mset(0, 0);
    1583                 :            : 
    1584         [ +  - ]:         14 :     Xapian::MSet mymset2 = enquire.get_mset(0, 1);
    1585                 :            : 
    1586 [ +  - ][ +  - ]:          7 :     TEST_EQUAL(mymset1.get_max_possible(), mymset2.get_max_possible());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1587                 :            : 
    1588                 :          7 :     return true;
    1589                 :            : }
    1590                 :            : 
    1591                 :            : // test that the matches_* of a simple query are as expected
    1592                 :          7 : DEFINE_TESTCASE(matches1, backend) {
    1593 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1594                 :         14 :     Xapian::Query myquery;
    1595         [ +  - ]:         14 :     Xapian::MSet mymset;
    1596                 :            : 
    1597 [ +  - ][ +  - ]:          7 :     myquery = query("word");
                 [ +  - ]
    1598         [ +  - ]:          7 :     enquire.set_query(myquery);
    1599 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
    1600 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1601 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1602 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1603 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1604 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1605 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1606                 :            : 
    1607 [ +  - ][ +  - ]:          7 :     myquery = query(Xapian::Query::OP_OR, "inmemory", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1608         [ +  - ]:          7 :     enquire.set_query(myquery);
    1609 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
    1610 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1611 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1612 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1613 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1614 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1615 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1616                 :            : 
    1617 [ +  - ][ +  - ]:          7 :     myquery = query(Xapian::Query::OP_AND, "inmemory", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1618         [ +  - ]:          7 :     enquire.set_query(myquery);
    1619 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
    1620 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1621 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1622 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1623 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1624 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1625 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 0);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1626                 :            : 
    1627 [ +  - ][ +  - ]:          7 :     myquery = query(Xapian::Query::OP_AND, "simple", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1628         [ +  - ]:          7 :     enquire.set_query(myquery);
    1629 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
    1630 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1631 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1632 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1633 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1634 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1635 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1636                 :            : 
    1637 [ +  - ][ +  - ]:          7 :     myquery = query(Xapian::Query::OP_AND, "simple", "word");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1638         [ +  - ]:          7 :     enquire.set_query(myquery);
    1639 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 0);
    1640                 :            :     // For a single database, this is true, but not for "multi" (since there
    1641                 :            :     // one sub-database has 3 documents and simple and word both have termfreq
    1642                 :            :     // of 2, so the matcher can tell at least one document must match!)
    1643                 :            :     // TEST_EQUAL(mymset.get_matches_lower_bound(), 0);
    1644 [ +  - ][ +  - ]:          7 :     TEST_REL(mymset.get_matches_lower_bound(),<=,mymset.get_matches_estimated());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1645 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1646 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1647 [ +  - ][ +  - ]:          7 :     TEST_REL(mymset.get_uncollapsed_matches_lower_bound(),<=,mymset.get_uncollapsed_matches_estimated());
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1648 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1649 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1650                 :            : 
    1651 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 1);
    1652 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1653 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1654 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1655 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1656 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1657 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1658                 :            : 
    1659 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 2);
    1660 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1661 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1662 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1663 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1664 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1665 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1666                 :            : 
    1667 [ +  - ][ +  - ]:          7 :     myquery = query(Xapian::Query::OP_AND, "paragraph", "another");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1668         [ +  - ]:          7 :     enquire.set_query(myquery);
    1669 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 0);
    1670 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1671 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1672 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1673 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1674 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1675 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1676                 :            : 
    1677 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 1);
    1678 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1679 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1680 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1681 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1682 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1683 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1684                 :            : 
    1685 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 2);
    1686 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1687 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1688 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1689 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1690 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1691 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1692                 :            : 
    1693 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(1, 20);
    1694 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1695 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_estimated(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1696 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_matches_upper_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1697 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_lower_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1698 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_estimated(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1699 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(mymset.get_uncollapsed_matches_upper_bound(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1700                 :            : 
    1701                 :          7 :     return true;
    1702                 :            : }
    1703                 :            : 
    1704                 :            : // tests that wqf affects the document weights
    1705                 :          7 : DEFINE_TESTCASE(wqf1, backend) {
    1706                 :            :     // Both queries have length 2; in q1 word has wqf=2, in q2 word has wqf=1
    1707 [ +  - ][ +  - ]:          7 :     Xapian::Query q1("word", 2);
    1708 [ +  - ][ +  - ]:         14 :     Xapian::Query q2("word");
    1709 [ +  - ][ +  - ]:         14 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1710         [ +  - ]:          7 :     enquire.set_query(q1);
    1711         [ +  - ]:         14 :     Xapian::MSet mset1 = enquire.get_mset(0, 10);
    1712         [ +  - ]:          7 :     enquire.set_query(q2);
    1713         [ +  - ]:         14 :     Xapian::MSet mset2 = enquire.get_mset(0, 2);
    1714                 :            :     // Check the weights
    1715 [ +  - ][ +  - ]:          7 :     TEST(mset1.begin().get_weight() > mset2.begin().get_weight());
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1716                 :          7 :     return true;
    1717                 :            : }
    1718                 :            : 
    1719                 :            : // tests that query length affects the document weights
    1720                 :          7 : DEFINE_TESTCASE(qlen1, backend) {
    1721 [ +  - ][ +  - ]:          7 :     Xapian::Query q1("word");
    1722 [ +  - ][ +  - ]:         14 :     Xapian::Query q2("word");
    1723 [ +  - ][ +  - ]:         14 :     Xapian::Enquire enquire(get_database("apitest_simpledata"));
                 [ +  - ]
    1724         [ +  - ]:          7 :     enquire.set_query(q1);
    1725         [ +  - ]:         14 :     Xapian::MSet mset1 = enquire.get_mset(0, 10);
    1726         [ +  - ]:          7 :     enquire.set_query(q2);
    1727         [ +  - ]:         14 :     Xapian::MSet mset2 = enquire.get_mset(0, 2);
    1728                 :            :     // Check the weights
    1729                 :            :     // TEST(mset1.begin().get_weight() < mset2.begin().get_weight());
    1730 [ +  - ][ +  - ]:          7 :     TEST(mset1.begin().get_weight() == mset2.begin().get_weight());
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1731                 :          7 :     return true;
    1732                 :            : }
    1733                 :            : 
    1734                 :            : // tests that opening a non-existent termlist throws the correct exception
    1735                 :          7 : DEFINE_TESTCASE(termlist1, backend) {
    1736 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_onedoc"));
    1737 [ +  - ][ -  + ]:          7 :     TEST_EXCEPTION(Xapian::InvalidArgumentError,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
    1738                 :            :                    Xapian::TermIterator t = db.termlist_begin(0));
    1739 [ +  - ][ -  +  :          7 :     TEST_EXCEPTION(Xapian::DocNotFoundError,
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
    1740                 :            :                    Xapian::TermIterator t = db.termlist_begin(2));
    1741                 :            :     /* Cause the database to be used properly, showing up problems
    1742                 :            :      * with the link being in a bad state.  CME */
    1743         [ +  - ]:         14 :     Xapian::TermIterator temp = db.termlist_begin(1);
    1744 [ +  - ][ -  +  :          7 :     TEST_EXCEPTION(Xapian::DocNotFoundError,
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ -  + ]
           [ -  +  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ +  - ]
    1745                 :            :                    Xapian::TermIterator t = db.termlist_begin(999999999));
    1746                 :          7 :     return true;
    1747                 :            : }
    1748                 :            : 
    1749                 :            : // tests that a Xapian::TermIterator works as an STL iterator
    1750                 :          7 : DEFINE_TESTCASE(termlist2, backend) {
    1751 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_onedoc"));
    1752         [ +  - ]:         14 :     Xapian::TermIterator t = db.termlist_begin(1);
    1753                 :         14 :     Xapian::TermIterator tend = db.termlist_end(1);
    1754                 :            : 
    1755                 :            :     // test operator= creates a copy which compares equal
    1756         [ +  - ]:         14 :     Xapian::TermIterator t_copy = t;
    1757 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(t, t_copy);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1758                 :            : 
    1759                 :            :     // test copy constructor creates a copy which compares equal
    1760         [ +  - ]:         14 :     Xapian::TermIterator t_clone(t);
    1761 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(t, t_clone);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1762                 :            : 
    1763 [ +  - ][ +  - ]:         14 :     vector<string> v(t, tend);
                 [ +  - ]
    1764                 :            : 
    1765 [ +  - ][ +  - ]:          7 :     t = db.termlist_begin(1);
    1766         [ +  - ]:          7 :     tend = db.termlist_end(1);
    1767                 :          7 :     vector<string>::const_iterator i;
    1768         [ +  + ]:         70 :     for (i = v.begin(); i != v.end(); ++i) {
    1769 [ -  + ][ #  # ]:         63 :         TEST_NOT_EQUAL(t, tend);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1770 [ +  - ][ -  + ]:         63 :         TEST_EQUAL(*i, *t);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1771         [ +  - ]:         63 :         t++;
    1772                 :            :     }
    1773 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(t, tend);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1774                 :          7 :     return true;
    1775                 :            : }
    1776                 :            : 
    1777                 :            : static Xapian::TermIterator
    1778                 :          7 : test_termlist3_helper()
    1779                 :            : {
    1780 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_onedoc"));
    1781         [ +  - ]:          7 :     return db.termlist_begin(1);
    1782                 :            : }
    1783                 :            : 
    1784                 :            : // tests that a Xapian::TermIterator still works when the DB is deleted
    1785                 :          7 : DEFINE_TESTCASE(termlist3, backend) {
    1786         [ +  - ]:          7 :     Xapian::TermIterator u = test_termlist3_helper();
    1787 [ +  - ][ +  - ]:         14 :     Xapian::Database db(get_database("apitest_onedoc"));
    1788         [ +  - ]:         14 :     Xapian::TermIterator t = db.termlist_begin(1);
    1789                 :         14 :     Xapian::TermIterator tend = db.termlist_end(1);
    1790                 :            : 
    1791         [ +  + ]:         70 :     while (t != tend) {
    1792 [ +  - ][ +  - ]:         63 :         TEST_EQUAL(*t, *u);
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1793         [ +  - ]:         63 :         t++;
    1794         [ +  - ]:         63 :         u++;
    1795                 :            :     }
    1796                 :          7 :     return true;
    1797                 :            : }
    1798                 :            : 
    1799                 :            : // tests skip_to
    1800                 :          7 : DEFINE_TESTCASE(termlist4, backend) {
    1801 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_onedoc"));
    1802         [ +  - ]:         14 :     Xapian::TermIterator i = db.termlist_begin(1);
    1803 [ +  - ][ +  - ]:          7 :     i.skip_to("");
    1804 [ +  - ][ +  - ]:          7 :     i.skip_to("\xff");
    1805                 :          7 :     return true;
    1806                 :            : }
    1807                 :            : 
    1808                 :            : // tests punctuation is OK in terms (particularly in remote queries)
    1809                 :          7 : DEFINE_TESTCASE(puncterms1, backend) {
    1810 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_punc"));
    1811         [ +  - ]:         14 :     Xapian::Enquire enquire(db);
    1812                 :            : 
    1813 [ +  - ][ +  - ]:         14 :     Xapian::Query q1("semi;colon");
    1814         [ +  - ]:          7 :     enquire.set_query(q1);
    1815         [ +  - ]:         14 :     Xapian::MSet m1 = enquire.get_mset(0, 10);
    1816                 :            : 
    1817 [ +  - ][ +  - ]:         14 :     Xapian::Query q2("col:on");
    1818         [ +  - ]:          7 :     enquire.set_query(q2);
    1819         [ +  - ]:         14 :     Xapian::MSet m2 = enquire.get_mset(0, 10);
    1820                 :            : 
    1821 [ +  - ][ +  - ]:         14 :     Xapian::Query q3("com,ma");
    1822         [ +  - ]:          7 :     enquire.set_query(q3);
    1823         [ +  - ]:          7 :     Xapian::MSet m3 = enquire.get_mset(0, 10);
    1824                 :            : 
    1825                 :          7 :     return true;
    1826                 :            : }
    1827                 :            : 
    1828                 :            : // test that searching for a term with a space or backslash in it works
    1829                 :          7 : DEFINE_TESTCASE(spaceterms1, backend) {
    1830 [ +  - ][ +  - ]:          7 :     Xapian::Enquire enquire(get_database("apitest_space"));
                 [ +  - ]
    1831         [ +  - ]:         14 :     Xapian::MSet mymset;
    1832                 :            :     Xapian::doccount count;
    1833         [ +  - ]:         14 :     Xapian::MSetIterator m;
    1834 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
    1835                 :            : 
    1836 [ +  - ][ +  - ]:          7 :     enquire.set_query(stemmer("space man"));
         [ +  - ][ +  - ]
    1837 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
    1838 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1839                 :          7 :     count = 0;
    1840 [ +  - ][ +  - ]:         14 :     for (m = mymset.begin(); m != mymset.end(); ++m) ++count;
         [ +  - ][ +  + ]
    1841 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(count, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1842                 :            : 
    1843         [ +  + ]:         49 :     for (Xapian::valueno value_no = 1; value_no < 7; ++value_no) {
    1844 [ +  - ][ +  - ]:         42 :         TEST_NOT_EQUAL(mymset.begin().get_document().get_data(), "");
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1845 [ +  - ][ +  - ]:         42 :         TEST_NOT_EQUAL(mymset.begin().get_document().get_value(value_no), "");
         [ +  - ][ +  - ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1846                 :            :     }
    1847                 :            : 
    1848 [ +  - ][ +  - ]:          7 :     enquire.set_query(stemmer("tab\tby"));
         [ +  - ][ +  - ]
    1849 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
    1850 [ +  - ][ -  + ]:          7 :     TEST_MSET_SIZE(mymset, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1851                 :          7 :     count = 0;
    1852 [ +  - ][ +  - ]:         14 :     for (m = mymset.begin(); m != mymset.end(); ++m) ++count;
         [ +  - ][ +  + ]
    1853 [ -  + ][ #  # ]:          7 :     TEST_EQUAL(count, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [