| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <config.h> |
|---|
| 24 | |
|---|
| 25 | #include <xapian/error.h> |
|---|
| 26 | #include <xapian/types.h> |
|---|
| 27 | |
|---|
| 28 | #include "flint_spellingwordslist.h" |
|---|
| 29 | #include "flint_utils.h" |
|---|
| 30 | #include "stringutils.h" |
|---|
| 31 | |
|---|
| 32 | FlintSpellingWordsList::~FlintSpellingWordsList() |
|---|
| 33 | { |
|---|
| 34 | DEBUGCALL(DB, void, "~FlintSpellingWordsList", ""); |
|---|
| 35 | delete cursor; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | Xapian::termcount |
|---|
| 39 | FlintSpellingWordsList::get_approx_size() const |
|---|
| 40 | { |
|---|
| 41 | DEBUGCALL(DB, Xapian::termcount, "FlintSpellingWordsList::get_approx_size", ""); |
|---|
| 42 | throw Xapian::UnimplementedError("FlintSpellingWordsList::get_approx_size() not implemented"); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | string |
|---|
| 46 | FlintSpellingWordsList::get_termname() const |
|---|
| 47 | { |
|---|
| 48 | DEBUGCALL(DB, string, "FlintSpellingWordsList::get_termname", ""); |
|---|
| 49 | Assert(cursor); |
|---|
| 50 | Assert(!at_end()); |
|---|
| 51 | Assert(!cursor->current_key.empty()); |
|---|
| 52 | Assert(cursor->current_key[0] == 'W'); |
|---|
| 53 | RETURN(cursor->current_key.substr(1)); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | Xapian::doccount |
|---|
| 57 | FlintSpellingWordsList::get_termfreq() const |
|---|
| 58 | { |
|---|
| 59 | DEBUGCALL(DB, string, "FlintSpellingWordsList::get_termfreq", ""); |
|---|
| 60 | Assert(cursor); |
|---|
| 61 | Assert(!at_end()); |
|---|
| 62 | Assert(!cursor->current_key.empty()); |
|---|
| 63 | Assert(cursor->current_key[0] == 'W'); |
|---|
| 64 | cursor->read_tag(); |
|---|
| 65 | |
|---|
| 66 | Xapian::termcount freq; |
|---|
| 67 | const char *p = cursor->current_tag.data(); |
|---|
| 68 | if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) { |
|---|
| 69 | throw Xapian::DatabaseCorruptError("Bad spelling word freq"); |
|---|
| 70 | } |
|---|
| 71 | return freq; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | Xapian::termcount |
|---|
| 75 | FlintSpellingWordsList::get_collection_freq() const |
|---|
| 76 | { |
|---|
| 77 | throw Xapian::InvalidOperationError("FlintSpellingWordsList::get_collection_freq() not meaningful"); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | TermList * |
|---|
| 81 | FlintSpellingWordsList::next() |
|---|
| 82 | { |
|---|
| 83 | DEBUGCALL(DB, TermList *, "FlintSpellingWordsList::next", ""); |
|---|
| 84 | Assert(!at_end()); |
|---|
| 85 | |
|---|
| 86 | cursor->next(); |
|---|
| 87 | if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) { |
|---|
| 88 | |
|---|
| 89 | cursor->to_end(); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | RETURN(NULL); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | TermList * |
|---|
| 96 | FlintSpellingWordsList::skip_to(const string &tname) |
|---|
| 97 | { |
|---|
| 98 | DEBUGCALL(DB, TermList *, "FlintSpellingWordsList::skip_to", tname); |
|---|
| 99 | Assert(!at_end()); |
|---|
| 100 | |
|---|
| 101 | if (!cursor->find_entry_ge("W" + tname)) { |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) { |
|---|
| 105 | |
|---|
| 106 | cursor->to_end(); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | RETURN(NULL); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | bool |
|---|
| 113 | FlintSpellingWordsList::at_end() const |
|---|
| 114 | { |
|---|
| 115 | DEBUGCALL(DB, bool, "FlintSpellingWordsList::at_end", ""); |
|---|
| 116 | RETURN(cursor->after_end()); |
|---|
| 117 | } |
|---|