| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #include <config.h> |
|---|
| 22 | |
|---|
| 23 | #include "flint_alltermslist.h" |
|---|
| 24 | #include "flint_postlist.h" |
|---|
| 25 | #include "flint_utils.h" |
|---|
| 26 | |
|---|
| 27 | #include "stringutils.h" |
|---|
| 28 | |
|---|
| 29 | void |
|---|
| 30 | FlintAllTermsList::read_termfreq_and_collfreq() const |
|---|
| 31 | { |
|---|
| 32 | DEBUGCALL(DB, void, "FlintAllTermsList::read_termfreq_and_collfreq", ""); |
|---|
| 33 | Assert(!current_term.empty()); |
|---|
| 34 | Assert(!at_end()); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | cursor->read_tag(); |
|---|
| 39 | const char *p = cursor->current_tag.data(); |
|---|
| 40 | const char *pend = p + cursor->current_tag.size(); |
|---|
| 41 | FlintPostList::read_number_of_entries(&p, pend, &termfreq, &collfreq); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | FlintAllTermsList::~FlintAllTermsList() |
|---|
| 45 | { |
|---|
| 46 | DEBUGCALL(DB, void, "~FlintAllTermsList", ""); |
|---|
| 47 | delete cursor; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | Xapian::termcount |
|---|
| 51 | FlintAllTermsList::get_approx_size() const |
|---|
| 52 | { |
|---|
| 53 | DEBUGCALL(DB, Xapian::termcount, "FlintAllTermsList::get_approx_size", ""); |
|---|
| 54 | RETURN(approx_size); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | string |
|---|
| 58 | FlintAllTermsList::get_termname() const |
|---|
| 59 | { |
|---|
| 60 | DEBUGCALL(DB, string, "FlintAllTermsList::get_termname", ""); |
|---|
| 61 | Assert(!current_term.empty()); |
|---|
| 62 | Assert(!at_end()); |
|---|
| 63 | RETURN(current_term); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | Xapian::doccount |
|---|
| 67 | FlintAllTermsList::get_termfreq() const |
|---|
| 68 | { |
|---|
| 69 | DEBUGCALL(DB, Xapian::doccount, "FlintAllTermsList::get_termfreq", ""); |
|---|
| 70 | Assert(!current_term.empty()); |
|---|
| 71 | Assert(!at_end()); |
|---|
| 72 | if (termfreq == 0) read_termfreq_and_collfreq(); |
|---|
| 73 | RETURN(termfreq); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | Xapian::termcount |
|---|
| 77 | FlintAllTermsList::get_collection_freq() const |
|---|
| 78 | { |
|---|
| 79 | DEBUGCALL(DB, Xapian::termcount, "FlintAllTermsList::get_collection_freq", ""); |
|---|
| 80 | Assert(!current_term.empty()); |
|---|
| 81 | Assert(!at_end()); |
|---|
| 82 | if (termfreq == 0) read_termfreq_and_collfreq(); |
|---|
| 83 | RETURN(collfreq); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | TermList * |
|---|
| 87 | FlintAllTermsList::next() |
|---|
| 88 | { |
|---|
| 89 | DEBUGCALL(DB, TermList *, "FlintAllTermsList::next", ""); |
|---|
| 90 | Assert(!at_end()); |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | termfreq = 0; |
|---|
| 94 | |
|---|
| 95 | while (true) { |
|---|
| 96 | cursor->next(); |
|---|
| 97 | if (cursor->after_end()) { |
|---|
| 98 | current_term = ""; |
|---|
| 99 | break; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | const char *p = cursor->current_key.data(); |
|---|
| 103 | const char *pend = p + cursor->current_key.size(); |
|---|
| 104 | if (!unpack_string_preserving_sort(&p, pend, current_term)) { |
|---|
| 105 | throw Xapian::DatabaseCorruptError("PostList table key has unexpected format"); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if (!startswith(current_term, prefix)) { |
|---|
| 109 | |
|---|
| 110 | cursor->to_end(); |
|---|
| 111 | current_term = ""; |
|---|
| 112 | break; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | if (p == pend) break; |
|---|
| 119 | } |
|---|
| 120 | RETURN(NULL); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | TermList * |
|---|
| 124 | FlintAllTermsList::skip_to(const string &term) |
|---|
| 125 | { |
|---|
| 126 | DEBUGCALL(DB, TermList *, "FlintAllTermsList::skip_to", term); |
|---|
| 127 | Assert(!at_end()); |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | termfreq = 0; |
|---|
| 131 | |
|---|
| 132 | if (cursor->find_entry_ge(pack_string_preserving_sort(term))) { |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | current_term = term; |
|---|
| 136 | } else { |
|---|
| 137 | if (cursor->after_end()) { |
|---|
| 138 | current_term = ""; |
|---|
| 139 | RETURN(NULL); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | const char *p = cursor->current_key.data(); |
|---|
| 143 | const char *pend = p + cursor->current_key.size(); |
|---|
| 144 | if (!unpack_string_preserving_sort(&p, pend, current_term)) { |
|---|
| 145 | throw Xapian::DatabaseCorruptError("PostList table key has unexpected format"); |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | if (!startswith(current_term, prefix)) { |
|---|
| 150 | |
|---|
| 151 | cursor->to_end(); |
|---|
| 152 | current_term = ""; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | RETURN(NULL); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | bool |
|---|
| 159 | FlintAllTermsList::at_end() const |
|---|
| 160 | { |
|---|
| 161 | DEBUGCALL(DB, bool, "FlintAllTermsList::at_end", ""); |
|---|
| 162 | RETURN(cursor->after_end()); |
|---|
| 163 | } |
|---|