xapian-core  1.4.27
chert_spellingwordslist.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2004,2005,2006,2007,2008 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 
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 
35 {
36  LOGCALL_DTOR(DB, "ChertSpellingWordsList");
37  delete cursor;
38 }
39 
40 string
42 {
43  LOGCALL(DB, string, "ChertSpellingWordsList::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  RETURN(cursor->current_key.substr(1));
49 }
50 
53 {
54  LOGCALL(DB, Xapian::doccount, "ChertSpellingWordsList::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  cursor->read_tag();
60 
61  Xapian::termcount freq;
62  const char *p = cursor->current_tag.data();
63  if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
64  throw Xapian::DatabaseCorruptError("Bad spelling word freq");
65  }
66  RETURN(freq);
67 }
68 
69 TermList *
71 {
72  LOGCALL(DB, TermList *, "ChertSpellingWordsList::next", NO_ARGS);
73  Assert(!at_end());
74 
75  cursor->next();
76  if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
77  // We've reached the end of the prefixed terms.
78  cursor->to_end();
79  }
80 
81  RETURN(NULL);
82 }
83 
84 TermList *
85 ChertSpellingWordsList::skip_to(const string &tname)
86 {
87  LOGCALL(DB, TermList *, "ChertSpellingWordsList::skip_to", tname);
88  Assert(!at_end());
89 
90  if (!cursor->find_entry_ge("W" + tname)) {
91  // The exact term we asked for isn't there, so check if the next
92  // term after it also has a W prefix.
93  if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
94  // We've reached the end of the prefixed terms.
95  cursor->to_end();
96  }
97  }
98  RETURN(NULL);
99 }
100 
101 bool
103 {
104  LOGCALL(DB, bool, "ChertSpellingWordsList::at_end", NO_ARGS);
105  RETURN(cursor->after_end());
106 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
typedefs for Xapian
ChertCursor * cursor
A cursor which runs through the spelling table reading termnames from the keys.
bool next()
Advance to the next key.
TermList * next()
Advance to the next term in the list.
#define LOGCALL_DTOR(CATEGORY, CLASS)
Definition: debuglog.h:490
void to_end()
Set the cursor to be off the end of the table.
Definition: chert_cursor.h:231
Abstract base class for termlists.
Definition: termlist.h:39
Xapian::doccount get_termfreq() const
Returns the term frequency of the current term.
Hierarchy of classes which Xapian can throw as exceptions.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
bool find_entry_ge(const string &key)
Position the cursor on the lowest entry with key >= key.
string current_tag
Current tag pointed to by cursor.
Definition: chert_cursor.h:154
std::string get_termname() const
Returns the current termname.
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:51
DatabaseCorruptError indicates database corruption was detected.
Definition: error.h:409
bool after_end() const
Determine whether cursor is off the end of table.
Definition: chert_cursor.h:238
string current_key
Current key pointed to by cursor.
Definition: chert_cursor.h:149
A termlist containing all words which are spelling targets.
bool at_end() const
True if we&#39;re off the end of the list.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
bool read_tag(bool keep_compressed=false)
Read the tag from the table and store it in current_tag.
Pack types into strings and unpack them again.
bool unpack_uint_last(const char **p, const char *end, U *result)
Decode an unsigned integer as the last item in a string.
Definition: pack.h:111
Various handy helpers which std::string really should provide.
TermList * skip_to(const std::string &tname)
Advance to the first term which is >= tname.
Debug logging macros.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487