| 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 <string> |
|---|
| 24 | |
|---|
| 25 | #include "flint_database.h" |
|---|
| 26 | #include "flint_alldocspostlist.h" |
|---|
| 27 | |
|---|
| 28 | #include "utils.h" |
|---|
| 29 | |
|---|
| 30 | using namespace std; |
|---|
| 31 | |
|---|
| 32 | FlintAllDocsPostList::~FlintAllDocsPostList() |
|---|
| 33 | { |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | Xapian::doccount |
|---|
| 37 | FlintAllDocsPostList::get_termfreq() const |
|---|
| 38 | { |
|---|
| 39 | return doccount; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | Xapian::docid |
|---|
| 43 | FlintAllDocsPostList::get_docid() const |
|---|
| 44 | { |
|---|
| 45 | return current_did; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | Xapian::doclength |
|---|
| 49 | FlintAllDocsPostList::get_doclength() const |
|---|
| 50 | { |
|---|
| 51 | DEBUGCALL(DB, Xapian::doclength, "FlintAllDocsPostList::get_doclength", ""); |
|---|
| 52 | Assert(current_did); |
|---|
| 53 | |
|---|
| 54 | cursor->read_tag(); |
|---|
| 55 | |
|---|
| 56 | if (cursor->current_tag.empty()) RETURN(0); |
|---|
| 57 | |
|---|
| 58 | const char * pos = cursor->current_tag.data(); |
|---|
| 59 | const char * end = pos + cursor->current_tag.size(); |
|---|
| 60 | |
|---|
| 61 | flint_doclen_t doclen; |
|---|
| 62 | if (!unpack_uint(&pos, end, &doclen)) { |
|---|
| 63 | const char *msg; |
|---|
| 64 | if (pos == 0) { |
|---|
| 65 | msg = "Too little data for doclen in termlist"; |
|---|
| 66 | } else { |
|---|
| 67 | msg = "Overflowed value for doclen in termlist"; |
|---|
| 68 | } |
|---|
| 69 | throw Xapian::DatabaseCorruptError(msg); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | RETURN(doclen); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | Xapian::termcount |
|---|
| 76 | FlintAllDocsPostList::get_wdf() const |
|---|
| 77 | { |
|---|
| 78 | DEBUGCALL(DB, Xapian::termcount, "FlintAllDocsPostList::get_wdf", ""); |
|---|
| 79 | Assert(current_did); |
|---|
| 80 | RETURN(1); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | PostList * |
|---|
| 84 | FlintAllDocsPostList::read_did_from_current_key() |
|---|
| 85 | { |
|---|
| 86 | DEBUGCALL(DB, PostList *, "FlintAllDocsPostList::read_did_from_current_key", |
|---|
| 87 | ""); |
|---|
| 88 | const string & key = cursor->current_key; |
|---|
| 89 | const char * pos = key.data(); |
|---|
| 90 | const char * end = pos + key.size(); |
|---|
| 91 | if (!unpack_uint_preserving_sort(&pos, end, ¤t_did)) { |
|---|
| 92 | const char *msg; |
|---|
| 93 | if (pos == 0) { |
|---|
| 94 | msg = "Too little data in termlist key"; |
|---|
| 95 | } else { |
|---|
| 96 | msg = "Overflowed value in termlist key"; |
|---|
| 97 | } |
|---|
| 98 | throw Xapian::DatabaseCorruptError(msg); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | RETURN(NULL); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | PostList * |
|---|
| 106 | FlintAllDocsPostList::next(Xapian::weight ) |
|---|
| 107 | { |
|---|
| 108 | DEBUGCALL(DB, PostList *, "FlintAllDocsPostList::next", "/*w_min*/"); |
|---|
| 109 | Assert(!at_end()); |
|---|
| 110 | if (!cursor->next()) RETURN(NULL); |
|---|
| 111 | RETURN(read_did_from_current_key()); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | PostList * |
|---|
| 115 | FlintAllDocsPostList::skip_to(Xapian::docid did, Xapian::weight ) |
|---|
| 116 | { |
|---|
| 117 | DEBUGCALL(DB, PostList *, "FlintAllDocsPostList::skip_to", |
|---|
| 118 | did << ", /*w_min*/"); |
|---|
| 119 | |
|---|
| 120 | if (did <= current_did || at_end()) RETURN(NULL); |
|---|
| 121 | |
|---|
| 122 | if (cursor->find_entry_ge(pack_uint_preserving_sort(did))) { |
|---|
| 123 | |
|---|
| 124 | current_did = did; |
|---|
| 125 | RETURN(NULL); |
|---|
| 126 | } |
|---|
| 127 | if (cursor->after_end()) RETURN(NULL); |
|---|
| 128 | |
|---|
| 129 | RETURN(read_did_from_current_key()); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | bool |
|---|
| 133 | FlintAllDocsPostList::at_end() const { |
|---|
| 134 | DEBUGCALL(DB, bool, "FlintAllDocsPostList::at_end", ""); |
|---|
| 135 | RETURN(cursor->after_end()); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | string |
|---|
| 139 | FlintAllDocsPostList::get_description() const |
|---|
| 140 | { |
|---|
| 141 | string desc = "FlintAllDocsPostList(did="; |
|---|
| 142 | desc += om_tostring(current_did); |
|---|
| 143 | desc += ",doccount="; |
|---|
| 144 | desc += om_tostring(doccount); |
|---|
| 145 | desc += ')'; |
|---|
| 146 | return desc; |
|---|
| 147 | } |
|---|