1 /** @file glass_spellingwordslist.cc
2 * @brief Iterator for the spelling correction words in a glass database.
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2017 Olly Betts
5 * Copyright (C) 2007 Lemur Consulting Ltd
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.
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.
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
24 #include "glass_spellingwordslist.h"
26 #include "xapian/error.h"
27 #include "xapian/types.h"
30 #include "glass_database.h"
32 #include "stringutils.h"
34 GlassSpellingWordsList::~GlassSpellingWordsList()
36 LOGCALL_DTOR(DB
, "GlassSpellingWordsList");
41 GlassSpellingWordsList::get_approx_size() const
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 return database
->spelling_table
.get_entry_count();
49 GlassSpellingWordsList::get_termname() const
51 LOGCALL(DB
, string
, "GlassSpellingWordsList::get_termname", NO_ARGS
);
54 Assert(!cursor
->current_key
.empty());
55 Assert(cursor
->current_key
[0] == 'W');
56 RETURN(cursor
->current_key
.substr(1));
60 GlassSpellingWordsList::get_termfreq() const
62 LOGCALL(DB
, Xapian::doccount
, "GlassSpellingWordsList::get_termfreq", NO_ARGS
);
65 Assert(!cursor
->current_key
.empty());
66 Assert(cursor
->current_key
[0] == 'W');
69 Xapian::termcount freq
;
70 const char *p
= cursor
->current_tag
.data();
71 if (!unpack_uint_last(&p
, p
+ cursor
->current_tag
.size(), &freq
)) {
72 throw Xapian::DatabaseCorruptError("Bad spelling word freq");
78 GlassSpellingWordsList::get_collection_freq() const
80 throw Xapian::InvalidOperationError("GlassSpellingWordsList::get_collection_freq() not meaningful");
84 GlassSpellingWordsList::next()
86 LOGCALL(DB
, TermList
*, "GlassSpellingWordsList::next", NO_ARGS
);
90 if (!cursor
->after_end() && !startswith(cursor
->current_key
, 'W')) {
91 // We've reached the end of the prefixed terms.
99 GlassSpellingWordsList::skip_to(const string
&tname
)
101 LOGCALL(DB
, TermList
*, "GlassSpellingWordsList::skip_to", tname
);
104 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 if (!cursor
->after_end() && !startswith(cursor
->current_key
, 'W')) {
108 // We've reached the end of the prefixed terms.
116 GlassSpellingWordsList::at_end() const
118 LOGCALL(DB
, bool, "GlassSpellingWordsList::at_end", NO_ARGS
);
119 RETURN(cursor
->after_end());