LCOV - code coverage report
Current view: top level - backends/brass - brass_spellingwordslist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 16 25 64.0 %
Date: 2011-08-21 Functions: 5 9 55.6 %
Branches: 7 28 25.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file brass_spellingwordslist.cc
       2                 :            :  * @brief Iterator for the spelling correction words in a brass database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2004,2005,2006,2007,2008,2009 Olly Betts
       5                 :            :  * Copyright (C) 2007 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : 
      25                 :            : #include "brass_spellingwordslist.h"
      26                 :            : 
      27                 :            : #include "xapian/error.h"
      28                 :            : #include "xapian/types.h"
      29                 :            : 
      30                 :            : #include "debuglog.h"
      31                 :            : #include "pack.h"
      32                 :            : #include "stringutils.h"
      33                 :            : 
      34                 :          5 : BrassSpellingWordsList::~BrassSpellingWordsList()
      35                 :            : {
      36                 :            :     LOGCALL_DTOR(DB, "BrassSpellingWordsList");
      37 [ +  - ][ #  # ]:          5 :     delete cursor;
                 [ #  # ]
      38 [ +  - ][ #  # ]:          5 : }
                 [ #  # ]
      39                 :            : 
      40                 :            : string
      41                 :          8 : BrassSpellingWordsList::get_termname() const
      42                 :            : {
      43                 :            :     LOGCALL(DB, string, "BrassSpellingWordsList::get_termname", NO_ARGS);
      44                 :            :     Assert(cursor);
      45                 :            :     Assert(!at_end());
      46                 :            :     Assert(!cursor->current_key.empty());
      47                 :            :     Assert(cursor->current_key[0] == 'W');
      48                 :          8 :     RETURN(cursor->current_key.substr(1));
      49                 :            : }
      50                 :            : 
      51                 :            : Xapian::doccount
      52                 :          8 : BrassSpellingWordsList::get_termfreq() const
      53                 :            : {
      54                 :            :     LOGCALL(DB, string, "BrassSpellingWordsList::get_termfreq", NO_ARGS);
      55                 :            :     Assert(cursor);
      56                 :            :     Assert(!at_end());
      57                 :            :     Assert(!cursor->current_key.empty());
      58                 :            :     Assert(cursor->current_key[0] == 'W');
      59                 :          8 :     cursor->read_tag();
      60                 :            : 
      61                 :            :     Xapian::termcount freq;
      62                 :          8 :     const char *p = cursor->current_tag.data();
      63         [ -  + ]:          8 :     if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
      64                 :          0 :         throw Xapian::DatabaseCorruptError("Bad spelling word freq");
      65                 :            :     }
      66                 :          8 :     return freq;
      67                 :            : }
      68                 :            : 
      69                 :            : Xapian::termcount
      70                 :          0 : BrassSpellingWordsList::get_collection_freq() const
      71                 :            : {
      72                 :          0 :     throw Xapian::InvalidOperationError("BrassSpellingWordsList::get_collection_freq() not meaningful");
      73                 :            : }
      74                 :            : 
      75                 :            : TermList *
      76                 :         13 : BrassSpellingWordsList::next()
      77                 :            : {
      78                 :            :     LOGCALL(DB, TermList *, "BrassSpellingWordsList::next", NO_ARGS);
      79                 :            :     Assert(!at_end());
      80                 :            : 
      81                 :         13 :     cursor->next();
      82   [ +  +  -  + ]:         13 :     if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
                 [ -  + ]
      83                 :            :         // We've reached the end of the prefixed terms.
      84                 :          0 :         cursor->to_end();
      85                 :            :     }
      86                 :            : 
      87                 :         13 :     RETURN(NULL);
      88                 :            : }
      89                 :            : 
      90                 :            : TermList *
      91                 :          0 : BrassSpellingWordsList::skip_to(const string &tname)
      92                 :            : {
      93                 :            :     LOGCALL(DB, TermList *, "BrassSpellingWordsList::skip_to", tname);
      94                 :            :     Assert(!at_end());
      95                 :            : 
      96         [ #  # ]:          0 :     if (!cursor->find_entry_ge("W" + tname)) {
      97                 :            :         // The exact term we asked for isn't there, so check if the next
      98                 :            :         // term after it also has a W prefix.
      99 [ #  # ][ #  # ]:          0 :         if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
                 [ #  # ]
     100                 :            :             // We've reached the end of the prefixed terms.
     101                 :          0 :             cursor->to_end();
     102                 :            :         }
     103                 :            :     }
     104                 :          0 :     RETURN(NULL);
     105                 :            : }
     106                 :            : 
     107                 :            : bool
     108                 :         13 : BrassSpellingWordsList::at_end() const
     109                 :            : {
     110                 :            :     LOGCALL(DB, bool, "BrassSpellingWordsList::at_end", NO_ARGS);
     111                 :         13 :     RETURN(cursor->after_end());
     112                 :            : }

Generated by: LCOV version 1.8