LCOV - code coverage report
Current view: top level - backends/honey - honey_spellingwordslist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 0 33 0.0 %
Date: 2019-05-16 09:13:18 Functions: 0 8 0.0 %
Branches: 0 40 0.0 %

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

Generated by: LCOV version 1.11