xapian-core  1.4.27
glass_spellingwordslist.cc
Go to the documentation of this file.
1 
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 #include <config.h>
23 
25 
26 #include "xapian/error.h"
27 #include "xapian/types.h"
28 
29 #include "debuglog.h"
30 #include "pack.h"
31 #include "stringutils.h"
32 
34 {
35  LOGCALL_DTOR(DB, "GlassSpellingWordsList");
36  delete cursor;
37 }
38 
39 string
41 {
42  LOGCALL(DB, string, "GlassSpellingWordsList::get_termname", NO_ARGS);
43  Assert(cursor);
44  Assert(!at_end());
45  Assert(!cursor->current_key.empty());
46  Assert(cursor->current_key[0] == 'W');
47  RETURN(cursor->current_key.substr(1));
48 }
49 
52 {
53  LOGCALL(DB, Xapian::doccount, "GlassSpellingWordsList::get_termfreq", NO_ARGS);
54  Assert(cursor);
55  Assert(!at_end());
56  Assert(!cursor->current_key.empty());
57  Assert(cursor->current_key[0] == 'W');
58  cursor->read_tag();
59 
60  Xapian::termcount freq;
61  const char *p = cursor->current_tag.data();
62  if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
63  throw Xapian::DatabaseCorruptError("Bad spelling word freq");
64  }
65  RETURN(freq);
66 }
67 
68 TermList *
70 {
71  LOGCALL(DB, TermList *, "GlassSpellingWordsList::next", NO_ARGS);
72  Assert(!at_end());
73 
74  cursor->next();
75  if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
76  // We've reached the end of the prefixed terms.
77  cursor->to_end();
78  }
79 
80  RETURN(NULL);
81 }
82 
83 TermList *
84 GlassSpellingWordsList::skip_to(const string &tname)
85 {
86  LOGCALL(DB, TermList *, "GlassSpellingWordsList::skip_to", tname);
87  Assert(!at_end());
88 
89  if (!cursor->find_entry_ge("W" + tname)) {
90  // The exact term we asked for isn't there, so check if the next
91  // term after it also has a W prefix.
92  if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
93  // We've reached the end of the prefixed terms.
94  cursor->to_end();
95  }
96  }
97  RETURN(NULL);
98 }
99 
100 bool
102 {
103  LOGCALL(DB, bool, "GlassSpellingWordsList::at_end", NO_ARGS);
104  RETURN(cursor->after_end());
105 }
#define RETURN(A)
Definition: debuglog.h:493
#define Assert(COND)
Definition: omassert.h:122
GlassCursor * cursor
A cursor which runs through the spelling table reading termnames from the keys.
typedefs for Xapian
#define LOGCALL_DTOR(CATEGORY, CLASS)
Definition: debuglog.h:490
std::string get_termname() const
Returns the current termname.
bool next()
Advance to the next key.
Abstract base class for termlists.
Definition: termlist.h:39
bool after_end() const
Determine whether cursor is off the end of table.
Definition: glass_cursor.h:329
bool read_tag(bool keep_compressed=false)
Read the tag from the table and store it in current_tag.
Hierarchy of classes which Xapian can throw as exceptions.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
Definition: types.h:72
A termlist containing all words which are spelling targets.
string current_key
Current key pointed to by cursor.
Definition: glass_cursor.h:239
string current_tag
Current tag pointed to by cursor.
Definition: glass_cursor.h:244
Xapian::doccount get_termfreq() const
Returns the term frequency of the current term.
bool startswith(const std::string &s, char pfx)
Definition: stringutils.h:51
bool find_entry_ge(const string &key)
Position the cursor on the lowest entry with key >= key.
DatabaseCorruptError indicates database corruption was detected.
Definition: error.h:409
TermList * skip_to(const std::string &tname)
Advance to the first term which is >= tname.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Definition: types.h:38
bool at_end() const
True if we&#39;re off the end of the list.
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 * next()
Advance to the next term in the list.
Debug logging macros.
void to_end()
Set the cursor to be off the end of the table.
Definition: glass_cursor.h:322
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
Definition: debuglog.h:487