[honey] Improve spelling table key encoding
[xapian.git] / xapian-core / backends / honey / honey_spellingwordslist.h
blobe77e99e4801d2b2dc78dfb5f2a44a1251f4b75ae
1 /** @file honey_spellingwordslist.h
2 * @brief A termlist containing all words which are spelling targets.
3 */
4 /* Copyright (C) 2005,2008,2009,2010,2011,2017 Olly Betts
5 * Copyright (C) 2007 Lemur Consulting Ltd
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (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
22 #ifndef XAPIAN_INCLUDED_HONEY_SPELLINGWORDSLIST_H
23 #define XAPIAN_INCLUDED_HONEY_SPELLINGWORDSLIST_H
25 #include "backends/alltermslist.h"
26 #include "honey_spelling.h"
27 #include "honey_cursor.h"
29 class HoneyDatabase;
31 class HoneySpellingWordsList : public AllTermsList {
32 /// Copying is not allowed.
33 HoneySpellingWordsList(const HoneySpellingWordsList &);
35 /// Assignment is not allowed.
36 void operator=(const HoneySpellingWordsList &);
38 /// Keep a reference to our database to stop it being deleted.
39 Xapian::Internal::intrusive_ptr<const HoneyDatabase> database;
41 /** A cursor which runs through the spelling table reading termnames from
42 * the keys.
44 HoneyCursor * cursor;
46 /** The term frequency of the term at the current position.
48 * If this value is zero, then we haven't read the term frequency or
49 * collection frequency for the current term yet. We need to call
50 * read_termfreq() to read these.
52 mutable Xapian::termcount termfreq;
54 /// Read and cache the term frequency.
55 void read_termfreq() const;
57 public:
58 HoneySpellingWordsList(const HoneyDatabase* database_, HoneyCursor* cursor_)
59 : database(database_), cursor(cursor_), termfreq(0) {
60 // Set the cursor to its end to signal we haven't started yet. Then
61 // if the first action is next() it can use find_entry_ge("\x04") to
62 // locate the first word.
63 cursor->to_end();
66 /// Destructor.
67 ~HoneySpellingWordsList();
69 Xapian::termcount get_approx_size() const;
71 /** Returns the current termname.
73 * Either next() or skip_to() must have been called before this
74 * method can be called.
76 std::string get_termname() const;
78 /** Returns the term frequency of the current term.
80 * Either next() or skip_to() must have been called before this
81 * method can be called.
83 Xapian::doccount get_termfreq() const;
85 /** Returns the collection frequency of the current term.
87 * Either next() or skip_to() must have been called before this
88 * method can be called.
90 Xapian::termcount get_collection_freq() const;
92 /// Advance to the next term in the list.
93 TermList * next();
95 /// Advance to the first term which is >= term.
96 TermList * skip_to(const std::string& term);
98 /// True if we're off the end of the list
99 bool at_end() const;
102 #endif /* XAPIAN_INCLUDED_HONEY_SPELLINGWORDSLIST_H */