LCOV - code coverage report
Current view: top level - tests - api_posdb.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 361 361 100.0 %
Date: 2019-06-30 05:20:33 Functions: 8 8 100.0 %
Branches: 674 2334 28.9 %

           Branch data     Line data    Source code
       1                 :            : /** @file api_posdb.cc
       2                 :            :  * @brief tests which need a backend with positional information
       3                 :            :  */
       4                 :            : /* Copyright 1999,2000,2001 BrightStation PLC
       5                 :            :  * Copyright 2002 Ananova Ltd
       6                 :            :  * Copyright 2002,2003,2004,2005,2006,2007,2009,2016,2019 Olly Betts
       7                 :            :  *
       8                 :            :  * This program is free software; you can redistribute it and/or
       9                 :            :  * modify it under the terms of the GNU General Public License as
      10                 :            :  * published by the Free Software Foundation; either version 2 of the
      11                 :            :  * License, or (at your option) any later version.
      12                 :            :  *
      13                 :            :  * This program is distributed in the hope that it will be useful,
      14                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16                 :            :  * GNU General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU General Public License
      19                 :            :  * along with this program; if not, write to the Free Software
      20                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      21                 :            :  * USA
      22                 :            :  */
      23                 :            : 
      24                 :            : #include <config.h>
      25                 :            : 
      26                 :            : #include "api_posdb.h"
      27                 :            : 
      28                 :            : #include <string>
      29                 :            : #include <vector>
      30                 :            : 
      31                 :            : using namespace std;
      32                 :            : 
      33                 :            : #include <xapian.h>
      34                 :            : #include "testsuite.h"
      35                 :            : #include "testutils.h"
      36                 :            : 
      37                 :            : #include "apitest.h"
      38                 :            : 
      39                 :            : /// Simple test of NEAR
      40                 :          7 : DEFINE_TESTCASE(near1, positional) {
      41 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_phrase"));
      42         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
      43 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
      44         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
      45                 :            : 
      46                 :            :     // make a query
      47                 :         14 :     vector<Xapian::Query> subqs;
      48                 :         14 :     Xapian::Query q;
      49 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
      50 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
      51 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
      52         [ +  - ]:          7 :     enquire.set_query(q);
      53                 :            : 
      54                 :            :     // retrieve the top ten results
      55         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
      56         [ +  - ]:          7 :     mset_expect_order(mymset);
      57                 :            : 
      58                 :          7 :     subqs.clear();
      59 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
      60 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
      61 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 2);
      62         [ +  - ]:          7 :     enquire.set_query(q);
      63                 :            : 
      64                 :            :     // retrieve the top ten results
      65 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
      66         [ +  - ]:          7 :     mset_expect_order(mymset, 3);
      67                 :            : 
      68                 :          7 :     subqs.clear();
      69 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
      70 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
      71 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 3);
      72         [ +  - ]:          7 :     enquire.set_query(q);
      73                 :            : 
      74                 :            :     // retrieve the top ten results
      75 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
      76         [ +  - ]:          7 :     mset_expect_order(mymset, 1, 3);
      77                 :            : 
      78                 :          7 :     subqs.clear();
      79 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
      80 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
      81 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 5);
      82         [ +  - ]:          7 :     enquire.set_query(q);
      83                 :            : 
      84                 :            :     // retrieve the top ten results
      85 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
      86         [ +  - ]:          7 :     mset_expect_order(mymset, 1, 3);
      87                 :            : 
      88                 :          7 :     subqs.clear();
      89 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
      90 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
      91 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 6);
      92         [ +  - ]:          7 :     enquire.set_query(q);
      93                 :            : 
      94                 :            :     // retrieve the top ten results
      95 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
      96         [ +  - ]:          7 :     mset_expect_order(mymset, 1, 2, 3);
      97                 :            : 
      98                 :          7 :     subqs.clear();
      99 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     100 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     101 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     102 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 3);
     103         [ +  - ]:          7 :     enquire.set_query(q);
     104                 :            : 
     105                 :            :     // retrieve the top ten results
     106 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     107         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9);
     108                 :            : 
     109                 :          7 :     subqs.clear();
     110 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     111 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     112 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     113 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 4);
     114         [ +  - ]:          7 :     enquire.set_query(q);
     115                 :            : 
     116                 :            :     // retrieve the top ten results
     117 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     118         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9, 10);
     119                 :            : 
     120                 :          7 :     subqs.clear();
     121 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     122 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     123 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     124 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 5);
     125         [ +  - ]:          7 :     enquire.set_query(q);
     126                 :            : 
     127                 :            :     // retrieve the top ten results
     128 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     129         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9, 10, 11);
     130                 :            : 
     131                 :          7 :     subqs.clear();
     132 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     133 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     134 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     135 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 6);
     136         [ +  - ]:          7 :     enquire.set_query(q);
     137                 :            : 
     138                 :            :     // retrieve the top ten results
     139 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     140         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9, 10, 11, 12);
     141                 :            : 
     142                 :          7 :     subqs.clear();
     143 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     144 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     145 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     146 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 7);
     147         [ +  - ]:          7 :     enquire.set_query(q);
     148                 :            : 
     149                 :            :     // retrieve the top twenty results
     150 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     151         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
     152                 :            : 
     153                 :          7 :     subqs.clear();
     154 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     155 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     156 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     157 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 8);
     158         [ +  - ]:          7 :     enquire.set_query(q);
     159                 :            : 
     160                 :            :     // retrieve the top twenty results
     161 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     162         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
     163                 :            : 
     164                 :          7 :     subqs.clear();
     165 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     166 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     167 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     168                 :            :     // test really large window size
     169 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 999999999);
     170         [ +  - ]:          7 :     enquire.set_query(q);
     171                 :            : 
     172                 :            :     // retrieve the top twenty results
     173 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     174         [ +  - ]:          7 :     mset_expect_order(mymset, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
     175                 :            : 
     176                 :          7 :     return true;
     177                 :            : }
     178                 :            : 
     179                 :            : /// Test NEAR over operators
     180                 :          7 : DEFINE_TESTCASE(near2, positional) {
     181 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_phrase"));
     182         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
     183 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
     184         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     185         [ +  - ]:         14 :     Xapian::MSet mymset;
     186                 :            : 
     187                 :            :     // make a query
     188                 :         14 :     vector<Xapian::Query> subqs;
     189                 :         14 :     Xapian::Query q;
     190                 :            :     subqs.push_back(Xapian::Query(Xapian::Query::OP_AND,
     191                 :            :                             Xapian::Query(stemmer("phrase")),
     192 [ +  - ][ +  - ]:          7 :                             Xapian::Query(stemmer("near"))));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     193 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("and")));
         [ +  - ][ +  - ]
     194 [ +  - ][ -  + ]:          7 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     195                 :            :         q = Xapian::Query(q.OP_NEAR, subqs.begin(), subqs.end(), 2);
     196                 :            :         enquire.set_query(q);
     197                 :            : 
     198                 :            :         // retrieve the top ten results
     199                 :            :         mymset = enquire.get_mset(0, 10)
     200                 :            :     );
     201                 :            : #if 0 // Disable until we reimplement this.
     202                 :            :     mset_expect_order(mymset, 1);
     203                 :            : 
     204                 :            :     subqs.clear();
     205                 :            :     subqs.push_back(Xapian::Query(Xapian::Query::OP_AND,
     206                 :            :                             Xapian::Query(stemmer("phrase")),
     207                 :            :                             Xapian::Query(stemmer("near"))));
     208                 :            :     subqs.push_back(Xapian::Query(stemmer("operator")));
     209                 :            :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 2);
     210                 :            :     enquire.set_query(q);
     211                 :            : 
     212                 :            :     // retrieve the top ten results
     213                 :            :     mymset = enquire.get_mset(0, 10);
     214                 :            :     mset_expect_order(mymset, 2);
     215                 :            : 
     216                 :            :     subqs.clear();
     217                 :            :     subqs.push_back(Xapian::Query(stemmer("operator")));
     218                 :            :     subqs.push_back(Xapian::Query(Xapian::Query::OP_AND,
     219                 :            :                             Xapian::Query(stemmer("phrase")),
     220                 :            :                             Xapian::Query(stemmer("near"))));
     221                 :            :     q = Xapian::Query(Xapian::Query::OP_NEAR, subqs.begin(), subqs.end(), 2);
     222                 :            :     enquire.set_query(q);
     223                 :            : 
     224                 :            :     // retrieve the top ten results
     225                 :            :     mymset = enquire.get_mset(0, 10);
     226                 :            :     mset_expect_order(mymset, 2);
     227                 :            : #endif
     228                 :            : 
     229                 :          7 :     return true;
     230                 :            : }
     231                 :            : 
     232                 :            : /// Simple test of PHRASE
     233                 :          7 : DEFINE_TESTCASE(phrase1, positional) {
     234 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_phrase"));
     235         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
     236 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
     237         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     238                 :            : 
     239                 :            :     // make a query
     240                 :         14 :     vector<Xapian::Query> subqs;
     241                 :         14 :     Xapian::Query q;
     242 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
     243 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     244 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
     245         [ +  - ]:          7 :     enquire.set_query(q);
     246                 :            : 
     247                 :            :     // retrieve the top ten results
     248         [ +  - ]:         14 :     Xapian::MSet mymset = enquire.get_mset(0, 10);
     249         [ +  - ]:          7 :     mset_expect_order(mymset);
     250                 :            : 
     251                 :          7 :     subqs.clear();
     252 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
     253 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
     254 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
     255         [ +  - ]:          7 :     enquire.set_query(q);
     256                 :            : 
     257                 :            :     // retrieve the top ten results
     258 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     259         [ +  - ]:          7 :     mset_expect_order(mymset);
     260                 :            : 
     261                 :          7 :     subqs.clear();
     262 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
     263 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
     264 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 3);
     265         [ +  - ]:          7 :     enquire.set_query(q);
     266                 :            : 
     267                 :            :     // retrieve the top ten results
     268 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     269         [ +  - ]:          7 :     mset_expect_order(mymset, 1);
     270                 :            : 
     271                 :          7 :     subqs.clear();
     272 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
     273 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
     274 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 5);
     275         [ +  - ]:          7 :     enquire.set_query(q);
     276                 :            : 
     277                 :            :     // retrieve the top ten results
     278 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     279         [ +  - ]:          7 :     mset_expect_order(mymset, 1);
     280                 :            : 
     281                 :          7 :     subqs.clear();
     282 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("phrase")));
         [ +  - ][ +  - ]
     283 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("near")));
         [ +  - ][ +  - ]
     284 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 6);
     285         [ +  - ]:          7 :     enquire.set_query(q);
     286                 :            : 
     287                 :            :     // retrieve the top ten results
     288 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     289         [ +  - ]:          7 :     mset_expect_order(mymset, 1, 2);
     290                 :            : 
     291                 :          7 :     subqs.clear();
     292 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     293 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     294 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     295 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 3);
     296         [ +  - ]:          7 :     enquire.set_query(q);
     297                 :            : 
     298                 :            :     // retrieve the top ten results
     299 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     300         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     301                 :            : 
     302                 :          7 :     subqs.clear();
     303 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     304 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     305 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     306 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 4);
     307         [ +  - ]:          7 :     enquire.set_query(q);
     308                 :            : 
     309                 :            :     // retrieve the top ten results
     310 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     311         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     312                 :            : 
     313                 :          7 :     subqs.clear();
     314 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     315 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     316 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     317 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 5);
     318         [ +  - ]:          7 :     enquire.set_query(q);
     319                 :            : 
     320                 :            :     // retrieve the top ten results
     321 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     322         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     323                 :            : 
     324                 :          7 :     subqs.clear();
     325 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     326 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     327 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     328 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 6);
     329         [ +  - ]:          7 :     enquire.set_query(q);
     330                 :            : 
     331                 :            :     // retrieve the top ten results
     332 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     333         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     334                 :            : 
     335                 :          7 :     subqs.clear();
     336 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     337 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     338 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     339 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 7);
     340         [ +  - ]:          7 :     enquire.set_query(q);
     341                 :            : 
     342                 :            :     // retrieve the top twenty results
     343 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     344         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     345                 :            : 
     346                 :          7 :     subqs.clear();
     347 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     348 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     349 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     350 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 8);
     351         [ +  - ]:          7 :     enquire.set_query(q);
     352                 :            : 
     353                 :            :     // retrieve the top 20 results
     354 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     355         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     356                 :            : 
     357                 :            :     // test really large window size
     358                 :          7 :     subqs.clear();
     359 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("leave")));
         [ +  - ][ +  - ]
     360 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("fridge")));
         [ +  - ][ +  - ]
     361 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("on")));
         [ +  - ][ +  - ]
     362 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 999999999);
     363         [ +  - ]:          7 :     enquire.set_query(q);
     364                 :            : 
     365                 :            :     // retrieve the top 20 results
     366 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 20);
     367         [ +  - ]:          7 :     mset_expect_order(mymset, 4);
     368                 :            : 
     369                 :            :     // regression test (was matching doc 15, should fail)
     370                 :          7 :     subqs.clear();
     371 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("first")));
         [ +  - ][ +  - ]
     372 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("second")));
         [ +  - ][ +  - ]
     373 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("third")));
         [ +  - ][ +  - ]
     374 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 9);
     375         [ +  - ]:          7 :     enquire.set_query(q);
     376                 :            : 
     377                 :            :     // retrieve the top ten results
     378 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     379         [ +  - ]:          7 :     mset_expect_order(mymset);
     380                 :            : 
     381                 :            :     // regression test (should match doc 15, make sure still does with fix)
     382                 :          7 :     subqs.clear();
     383 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("first")));
         [ +  - ][ +  - ]
     384 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("second")));
         [ +  - ][ +  - ]
     385 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("third")));
         [ +  - ][ +  - ]
     386 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 10);
     387         [ +  - ]:          7 :     enquire.set_query(q);
     388                 :            : 
     389                 :            :     // retrieve the top ten results
     390 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     391         [ +  - ]:          7 :     mset_expect_order(mymset, 15);
     392                 :            : 
     393                 :            :     // regression test (phrase matching was getting order wrong when
     394                 :            :     // build_and_tree reordered vector of PostLists)
     395                 :          7 :     subqs.clear();
     396 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("milk")));
         [ +  - ][ +  - ]
     397 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("rare")));
         [ +  - ][ +  - ]
     398 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
     399         [ +  - ]:          7 :     enquire.set_query(q);
     400                 :            : 
     401                 :            :     // retrieve the top ten results
     402 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     403         [ +  - ]:          7 :     mset_expect_order(mymset, 16);
     404                 :            : 
     405                 :            :     // regression test (phrase matching was getting order wrong when
     406                 :            :     // build_and_tree reordered vector of PostLists)
     407                 :          7 :     subqs.clear();
     408 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("rare")));
         [ +  - ][ +  - ]
     409 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("milk")));
         [ +  - ][ +  - ]
     410 [ +  - ][ +  - ]:          7 :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
     411         [ +  - ]:          7 :     enquire.set_query(q);
     412                 :            : 
     413                 :            :     // retrieve the top ten results
     414 [ +  - ][ +  - ]:          7 :     mymset = enquire.get_mset(0, 10);
     415         [ +  - ]:          7 :     mset_expect_order(mymset, 17);
     416                 :            : 
     417                 :          7 :     return true;
     418                 :            : }
     419                 :            : 
     420                 :            : /// Test PHRASE over operators
     421                 :          7 : DEFINE_TESTCASE(phrase2, positional) {
     422 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_phrase"));
     423         [ +  - ]:         14 :     Xapian::Enquire enquire(mydb);
     424 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
     425         [ +  - ]:          7 :     enquire.set_weighting_scheme(Xapian::BoolWeight());
     426         [ +  - ]:         14 :     Xapian::MSet mymset;
     427                 :            : 
     428                 :            :     // make a query
     429                 :         14 :     vector<Xapian::Query> subqs;
     430                 :         14 :     Xapian::Query q;
     431                 :            :     subqs.push_back(Xapian::Query(Xapian::Query::OP_AND,
     432                 :            :                             Xapian::Query(stemmer("phrase")),
     433 [ +  - ][ +  - ]:          7 :                             Xapian::Query(stemmer("near"))));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     434 [ +  - ][ +  - ]:          7 :     subqs.push_back(Xapian::Query(stemmer("and")));
         [ +  - ][ +  - ]
     435 [ +  - ][ -  + ]:          7 :     TEST_EXCEPTION(Xapian::UnimplementedError,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ -  + ][ -  +  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
                 [ +  - ]
     436                 :            :         q = Xapian::Query(q.OP_PHRASE, subqs.begin(), subqs.end(), 2);
     437                 :            :         enquire.set_query(q);
     438                 :            : 
     439                 :            :         // retrieve the top ten results
     440                 :            :         mymset = enquire.get_mset(0, 10)
     441                 :            :     );
     442                 :            : #if 0 // Disable until we reimplement this.
     443                 :            :     mset_expect_order(mymset);
     444                 :            : 
     445                 :            :     subqs.clear();
     446                 :            :     subqs.push_back(Xapian::Query(Xapian::Query::OP_AND,
     447                 :            :                             Xapian::Query(stemmer("phrase")),
     448                 :            :                             Xapian::Query(stemmer("near"))));
     449                 :            :     subqs.push_back(Xapian::Query(stemmer("operator")));
     450                 :            :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
     451                 :            :     enquire.set_query(q);
     452                 :            : 
     453                 :            :     // retrieve the top ten results
     454                 :            :     mymset = enquire.get_mset(0, 10);
     455                 :            :     mset_expect_order(mymset, 2);
     456                 :            : 
     457                 :            :     subqs.clear();
     458                 :            :     subqs.push_back(Xapian::Query(stemmer("operator")));
     459                 :            :     subqs.push_back(Xapian::Query(Xapian::Query::OP_AND,
     460                 :            :                             Xapian::Query(stemmer("phrase")),
     461                 :            :                             Xapian::Query(stemmer("near"))));
     462                 :            :     q = Xapian::Query(Xapian::Query::OP_PHRASE, subqs.begin(), subqs.end(), 2);
     463                 :            :     enquire.set_query(q);
     464                 :            : 
     465                 :            :     // retrieve the top ten results
     466                 :            :     mymset = enquire.get_mset(0, 10);
     467                 :            :     mset_expect_order(mymset);
     468                 :            : #endif
     469                 :            : 
     470                 :          7 :     return true;
     471                 :            : }
     472                 :            : 
     473                 :            : /// Test getting position lists from databases
     474                 :          7 : DEFINE_TESTCASE(poslist1, positional) {
     475 [ +  - ][ +  - ]:          7 :     Xapian::Database mydb(get_database("apitest_poslist"));
     476                 :            : 
     477 [ +  - ][ +  - ]:         14 :     Xapian::Stem stemmer("english");
     478 [ +  - ][ +  - ]:         14 :     string term = stemmer("sponge");
     479                 :            : 
     480         [ +  - ]:         14 :     Xapian::PositionIterator pli = mydb.positionlist_begin(2, term);
     481                 :            : 
     482 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     483 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     484         [ +  - ]:          7 :     pli++;
     485 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     486 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     487         [ +  - ]:          7 :     pli++;
     488 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     489 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 3);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     490         [ +  - ]:          7 :     pli++;
     491 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     492 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     493         [ +  - ]:          7 :     pli++;
     494 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     495 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 8);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     496         [ +  - ]:          7 :     pli++;
     497 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     498 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 13);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     499         [ +  - ]:          7 :     pli++;
     500 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     501 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 21);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     502         [ +  - ]:          7 :     pli++;
     503 [ -  + ][ #  # ]:          7 :     TEST(pli != mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     504 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(*pli, 34);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     505         [ +  - ]:          7 :     pli++;
     506 [ -  + ][ #  # ]:          7 :     TEST(pli == mydb.positionlist_end(2, term));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     507                 :            : 
     508                 :          7 :     return true;
     509                 :            : }
     510                 :            : 
     511                 :          5 : DEFINE_TESTCASE(poslist2, positional && writable) {
     512 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     513                 :            : 
     514         [ +  - ]:         10 :     Xapian::Document doc;
     515 [ +  - ][ +  - ]:          5 :     doc.add_term("nopos");
     516         [ +  - ]:          5 :     Xapian::docid did = db.add_document(doc);
     517                 :            : 
     518                 :            :     // Check what happens when term doesn't exist - should give an empty list.
     519                 :            :     // Threw RangeError in Xapian < 1.1.0.
     520 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.positionlist_begin(did, "nosuchterm"),
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     521                 :            :                db.positionlist_end(did, "nosuchterm"));
     522                 :            : 
     523                 :            :     // Check what happens when the document doesn't even exist - should give
     524                 :            :     // an empty list.  Threw DocNotFoundError in Xapian < 1.1.0.
     525 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.positionlist_begin(123, "nosuchterm"),
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     526                 :            :                db.positionlist_end(123, "nosuchterm"));
     527                 :            : 
     528 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.positionlist_begin(did, "nopos"),
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     529                 :            :                db.positionlist_end(did, "nopos"));
     530                 :            : 
     531         [ +  - ]:         10 :     Xapian::Document doc2 = db.get_document(did);
     532                 :            : 
     533         [ +  - ]:         10 :     Xapian::TermIterator term = doc2.termlist_begin();
     534                 :            : 
     535                 :            :     {
     536         [ +  - ]:          5 :         Xapian::PositionIterator i = term.positionlist_begin();
     537 [ -  + ][ #  # ]:          5 :         TEST_EQUAL(i, term.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     538                 :            :     }
     539                 :            : 
     540         [ +  - ]:         10 :     Xapian::Document doc3;
     541 [ +  - ][ +  - ]:          5 :     doc3.add_posting("hadpos", 1);
     542         [ +  - ]:          5 :     Xapian::docid did2 = db.add_document(doc3);
     543                 :            : 
     544         [ +  - ]:         10 :     Xapian::Document doc4 = db.get_document(did2);
     545 [ +  - ][ +  - ]:          5 :     doc4.remove_posting("hadpos", 1);
     546         [ +  - ]:          5 :     db.replace_document(did2, doc4);
     547                 :            :     // Removing the last position should remove the term if the wdf is 0
     548                 :            :     // (since 1.5.0).
     549 [ +  - ][ +  - ]:          5 :     TEST(!db.term_exists("hadpos"));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     550                 :            :     {
     551 [ +  - ][ +  - ]:          5 :         Xapian::PositionIterator i = db.positionlist_begin(did2, "hadpos");
     552 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(i, db.positionlist_end(did2, "hadpos"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     553                 :            :     }
     554                 :            : 
     555 [ +  - ][ +  - ]:          5 :     doc4.add_posting("extrawdf", 12, 2);
     556 [ +  - ][ +  - ]:          5 :     doc4.remove_posting("extrawdf", 12);
     557         [ +  - ]:          5 :     db.replace_document(did2, doc4);
     558                 :            :     // Removing the last position should leave the term if the wdf is non-zero.
     559 [ +  - ][ +  - ]:          5 :     TEST(db.term_exists("extrawdf"));
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     560                 :            :     {
     561 [ +  - ][ +  - ]:          5 :         Xapian::PositionIterator i = db.positionlist_begin(did2, "extrawdf");
     562 [ +  - ][ -  + ]:          5 :         TEST_EQUAL(i, db.positionlist_end(did2, "extrawdf"));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     563                 :            :     }
     564                 :            : 
     565         [ +  - ]:          5 :     db.delete_document(did);
     566                 :            :     // Check what happens when the document doesn't exist (but once did).
     567 [ +  - ][ +  - ]:          5 :     TEST_EQUAL(db.positionlist_begin(did, "nosuchterm"),
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     568                 :            :                db.positionlist_end(did, "nosuchterm"));
     569                 :            : 
     570                 :          5 :     return true;
     571                 :            : }
     572                 :            : 
     573                 :            : /// Test playing with a positionlist, testing skip_to in particular.
     574                 :            : /// (used to be quartztest's test_positionlist1).
     575                 :          5 : DEFINE_TESTCASE(poslist3, positional && writable) {
     576 [ +  - ][ +  - ]:          5 :     Xapian::WritableDatabase db = get_writable_database();
     577                 :            : 
     578         [ +  - ]:         10 :     Xapian::Document document;
     579 [ +  - ][ +  - ]:          5 :     document.add_posting("foo", 5);
     580 [ +  - ][ +  - ]:          5 :     document.add_posting("foo", 8);
     581 [ +  - ][ +  - ]:          5 :     document.add_posting("foo", 10);
     582 [ +  - ][ +  - ]:          5 :     document.add_posting("foo", 12);
     583         [ +  - ]:          5 :     db.add_document(document);
     584                 :            : 
     585 [ +  - ][ +  - ]:         10 :     Xapian::PositionIterator pl = db.positionlist_begin(1, "foo");
     586         [ +  - ]:         10 :     Xapian::PositionIterator pl_end = db.positionlist_end(1, "foo");
     587                 :            : 
     588 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     589 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     590         [ +  - ]:          5 :     ++pl;
     591 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     592 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 8);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     593         [ +  - ]:          5 :     ++pl;
     594 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     595 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     596         [ +  - ]:          5 :     ++pl;
     597 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     598 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 12);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     599         [ +  - ]:          5 :     ++pl;
     600 [ -  + ][ #  # ]:          5 :     TEST(pl == pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     601                 :            : 
     602 [ +  - ][ +  - ]:          5 :     pl = db.positionlist_begin(1, "foo");
                 [ +  - ]
     603         [ +  - ]:          5 :     pl.skip_to(5);
     604 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     605 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 5);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     606                 :            : 
     607         [ +  - ]:          5 :     pl.skip_to(9);
     608 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     609 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 10);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     610                 :            : 
     611         [ +  - ]:          5 :     ++pl;
     612 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     613 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 12);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     614                 :            : 
     615         [ +  - ]:          5 :     pl.skip_to(12);
     616 [ -  + ][ #  # ]:          5 :     TEST(pl != pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     617 [ +  - ][ -  + ]:          5 :     TEST_EQUAL(*pl, 12);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     618                 :            : 
     619         [ +  - ]:          5 :     pl.skip_to(13);
     620 [ -  + ][ #  # ]:          5 :     TEST(pl == pl_end);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     621                 :            : 
     622                 :          5 :     return true;
     623                 :            : }
     624                 :            : 
     625                 :            : // Regression test - in 0.9.4 (and many previous versions) you couldn't get a
     626                 :            : // PositionIterator from a TermIterator from Database::termlist_begin().
     627                 :            : //
     628                 :            : // Also test that positionlist_count() is implemented for this case, which it
     629                 :            : // wasn't in 1.0.2 and earlier.
     630                 :          7 : DEFINE_TESTCASE(positfromtermit1, positional) {
     631 [ +  - ][ +  - ]:          7 :     Xapian::Database db(get_database("apitest_phrase"));
     632         [ +  - ]:         14 :     Xapian::TermIterator t(db.termlist_begin(7));
     633 [ -  + ][ #  # ]:          7 :     TEST_NOT_EQUAL(t, db.termlist_end(7));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     634         [ +  - ]:         14 :     Xapian::PositionIterator p = t.positionlist_begin();
     635 [ -  + ][ #  # ]:          7 :     TEST_NOT_EQUAL(p, t.positionlist_end());
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     636                 :            : 
     637 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(t.positionlist_count(), 1);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     638 [ +  - ][ +  - ]:          7 :     t.skip_to("on");
     639 [ -  + ][ #  # ]:          7 :     TEST_NOT_EQUAL(t, db.termlist_end(7));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     640 [ +  - ][ -  + ]:          7 :     TEST_EQUAL(t.positionlist_count(), 2);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     641                 :            : 
     642                 :          7 :     return true;
     643                 :            : }

Generated by: LCOV version 1.11