LCOV - code coverage report
Current view: top level - backends/glass - glass_spellingwordslist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 18 27 66.7 %
Date: 2019-02-17 14:59:59 Functions: 6 8 75.0 %
Branches: 8 36 22.2 %

           Branch data     Line data    Source code
       1                 :            : /** @file glass_spellingwordslist.cc
       2                 :            :  * @brief Iterator for the spelling correction words in a glass database.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2004,2005,2006,2007,2008,2009,2017 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                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "glass_spellingwordslist.h"
      25                 :            : 
      26                 :            : #include "xapian/error.h"
      27                 :            : #include "xapian/types.h"
      28                 :            : 
      29                 :            : #include "debuglog.h"
      30                 :            : #include "glass_database.h"
      31                 :            : #include "pack.h"
      32                 :            : #include "stringutils.h"
      33                 :            : 
      34                 :         24 : GlassSpellingWordsList::~GlassSpellingWordsList()
      35                 :            : {
      36                 :            :     LOGCALL_DTOR(DB, "GlassSpellingWordsList");
      37         [ +  - ]:          8 :     delete cursor;
      38         [ -  + ]:         16 : }
      39                 :            : 
      40                 :            : Xapian::termcount
      41                 :          2 : GlassSpellingWordsList::get_approx_size() const
      42                 :            : {
      43                 :            :     // This is an over-estimate, but we only use this value to build a balanced
      44                 :            :     // or-tree, and it'll do a decent enough job for that.
      45                 :          2 :     return database->spelling_table.get_entry_count();
      46                 :            : }
      47                 :            : 
      48                 :            : string
      49                 :         12 : GlassSpellingWordsList::get_termname() const
      50                 :            : {
      51                 :            :     LOGCALL(DB, string, "GlassSpellingWordsList::get_termname", NO_ARGS);
      52                 :            :     Assert(cursor);
      53                 :            :     Assert(!at_end());
      54                 :            :     Assert(!cursor->current_key.empty());
      55                 :            :     Assert(cursor->current_key[0] == 'W');
      56                 :         12 :     RETURN(cursor->current_key.substr(1));
      57                 :            : }
      58                 :            : 
      59                 :            : Xapian::doccount
      60                 :          8 : GlassSpellingWordsList::get_termfreq() const
      61                 :            : {
      62                 :            :     LOGCALL(DB, Xapian::doccount, "GlassSpellingWordsList::get_termfreq", NO_ARGS);
      63                 :            :     Assert(cursor);
      64                 :            :     Assert(!at_end());
      65                 :            :     Assert(!cursor->current_key.empty());
      66                 :            :     Assert(cursor->current_key[0] == 'W');
      67         [ +  - ]:          8 :     cursor->read_tag();
      68                 :            : 
      69                 :            :     Xapian::termcount freq;
      70                 :          8 :     const char *p = cursor->current_tag.data();
      71         [ -  + ]:          8 :     if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
      72 [ #  # ][ #  # ]:          0 :         throw Xapian::DatabaseCorruptError("Bad spelling word freq");
                 [ #  # ]
      73                 :            :     }
      74                 :          8 :     RETURN(freq);
      75                 :            : }
      76                 :            : 
      77                 :            : Xapian::termcount
      78                 :          0 : GlassSpellingWordsList::get_collection_freq() const
      79                 :            : {
      80 [ #  # ][ #  # ]:          0 :     throw Xapian::InvalidOperationError("GlassSpellingWordsList::get_collection_freq() not meaningful");
                 [ #  # ]
      81                 :            : }
      82                 :            : 
      83                 :            : TermList *
      84                 :         20 : GlassSpellingWordsList::next()
      85                 :            : {
      86                 :            :     LOGCALL(DB, TermList *, "GlassSpellingWordsList::next", NO_ARGS);
      87                 :            :     Assert(!at_end());
      88                 :            : 
      89                 :         20 :     cursor->next();
      90 [ +  + ][ -  + ]:         20 :     if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
                 [ -  + ]
      91                 :            :         // We've reached the end of the prefixed terms.
      92                 :          0 :         cursor->to_end();
      93                 :            :     }
      94                 :            : 
      95                 :         20 :     RETURN(NULL);
      96                 :            : }
      97                 :            : 
      98                 :            : TermList *
      99                 :          0 : GlassSpellingWordsList::skip_to(const string &tname)
     100                 :            : {
     101                 :            :     LOGCALL(DB, TermList *, "GlassSpellingWordsList::skip_to", tname);
     102                 :            :     Assert(!at_end());
     103                 :            : 
     104 [ #  # ][ #  # ]:          0 :     if (!cursor->find_entry_ge("W" + tname)) {
     105                 :            :         // The exact term we asked for isn't there, so check if the next
     106                 :            :         // term after it also has a W prefix.
     107 [ #  # ][ #  # ]:          0 :         if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
                 [ #  # ]
     108                 :            :             // We've reached the end of the prefixed terms.
     109                 :          0 :             cursor->to_end();
     110                 :            :         }
     111                 :            :     }
     112                 :          0 :     RETURN(NULL);
     113                 :            : }
     114                 :            : 
     115                 :            : bool
     116                 :         20 : GlassSpellingWordsList::at_end() const
     117                 :            : {
     118                 :            :     LOGCALL(DB, bool, "GlassSpellingWordsList::at_end", NO_ARGS);
     119                 :         20 :     RETURN(cursor->after_end());
     120                 :            : }

Generated by: LCOV version 1.11