| 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_database.h" |
|---|
| 24 | #include "flint_modifiedpostlist.h" |
|---|
| 25 | |
|---|
| 26 | FlintModifiedPostList::~FlintModifiedPostList() |
|---|
| 27 | { |
|---|
| 28 | delete poslist; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void |
|---|
| 32 | FlintModifiedPostList::skip_deletes(Xapian::weight w_min) |
|---|
| 33 | { |
|---|
| 34 | while (!FlintPostList::at_end()) { |
|---|
| 35 | if (it == mods.end()) return; |
|---|
| 36 | if (it->first != FlintPostList::get_docid()) return; |
|---|
| 37 | if (it->second.first != 'D') return; |
|---|
| 38 | ++it; |
|---|
| 39 | FlintPostList::next(w_min); |
|---|
| 40 | } |
|---|
| 41 | while (it != mods.end() && it->second.first == 'D') ++it; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | Xapian::doccount |
|---|
| 45 | FlintModifiedPostList::get_termfreq() const |
|---|
| 46 | { |
|---|
| 47 | return this_db->get_termfreq(tname); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | Xapian::docid |
|---|
| 51 | FlintModifiedPostList::get_docid() const |
|---|
| 52 | { |
|---|
| 53 | if (it == mods.end()) return FlintPostList::get_docid(); |
|---|
| 54 | if (FlintPostList::at_end()) return it->first; |
|---|
| 55 | return min(it->first, FlintPostList::get_docid()); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | Xapian::doclength |
|---|
| 59 | FlintModifiedPostList::get_doclength() const |
|---|
| 60 | { |
|---|
| 61 | DEBUGCALL(DB, Xapian::doclength, "FlintModifiedPostList::get_doclength", ""); |
|---|
| 62 | if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) |
|---|
| 63 | RETURN(this_db->get_doclength(it->first)); |
|---|
| 64 | RETURN(FlintPostList::get_doclength()); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | Xapian::termcount |
|---|
| 68 | FlintModifiedPostList::get_wdf() const |
|---|
| 69 | { |
|---|
| 70 | if (FlintPostList::at_end()) return it->second.second; |
|---|
| 71 | Xapian::docid unmod_did = FlintPostList::get_docid(); |
|---|
| 72 | if (it != mods.end() && it->first <= unmod_did) { |
|---|
| 73 | if (it->first < unmod_did) return it->second.second; |
|---|
| 74 | return FlintPostList::get_wdf() + it->second.second; |
|---|
| 75 | } |
|---|
| 76 | return FlintPostList::get_wdf(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | PositionList * |
|---|
| 80 | FlintModifiedPostList::read_position_list() |
|---|
| 81 | { |
|---|
| 82 | if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) { |
|---|
| 83 | if (poslist) { |
|---|
| 84 | delete poslist; |
|---|
| 85 | poslist = NULL; |
|---|
| 86 | } |
|---|
| 87 | poslist = this_db->open_position_list(it->first, tname); |
|---|
| 88 | return poslist; |
|---|
| 89 | } |
|---|
| 90 | return FlintPostList::read_position_list(); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | PositionList * |
|---|
| 94 | FlintModifiedPostList::open_position_list() const |
|---|
| 95 | { |
|---|
| 96 | if (it != mods.end() && (FlintPostList::at_end() || it->first <= FlintPostList::get_docid())) { |
|---|
| 97 | return this_db->open_position_list(it->first, tname); |
|---|
| 98 | } |
|---|
| 99 | return FlintPostList::open_position_list(); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | PostList * |
|---|
| 103 | FlintModifiedPostList::next(Xapian::weight w_min) |
|---|
| 104 | { |
|---|
| 105 | if (have_started) { |
|---|
| 106 | if (FlintPostList::at_end()) { |
|---|
| 107 | ++it; |
|---|
| 108 | skip_deletes(w_min); |
|---|
| 109 | return NULL; |
|---|
| 110 | } |
|---|
| 111 | Xapian::docid unmod_did = FlintPostList::get_docid(); |
|---|
| 112 | if (it != mods.end() && it->first <= unmod_did) { |
|---|
| 113 | if (it->first < unmod_did && it->second.first != 'D') { |
|---|
| 114 | ++it; |
|---|
| 115 | skip_deletes(w_min); |
|---|
| 116 | return NULL; |
|---|
| 117 | } |
|---|
| 118 | ++it; |
|---|
| 119 | } |
|---|
| 120 | } |
|---|
| 121 | FlintPostList::next(w_min); |
|---|
| 122 | skip_deletes(w_min); |
|---|
| 123 | return NULL; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | PostList * |
|---|
| 127 | FlintModifiedPostList::skip_to(Xapian::docid desired_did, Xapian::weight w_min) |
|---|
| 128 | { |
|---|
| 129 | if (!FlintPostList::at_end()) FlintPostList::skip_to(desired_did, w_min); |
|---|
| 130 | |
|---|
| 131 | while (it != mods.end() && it->first < desired_did) ++it; |
|---|
| 132 | skip_deletes(w_min); |
|---|
| 133 | return NULL; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | bool |
|---|
| 137 | FlintModifiedPostList::at_end() const { |
|---|
| 138 | return it == mods.end() && FlintPostList::at_end(); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | std::string |
|---|
| 142 | FlintModifiedPostList::get_description() const |
|---|
| 143 | { |
|---|
| 144 | std::string desc = "FlintModifiedPostList("; |
|---|
| 145 | desc += FlintPostList::get_description(); |
|---|
| 146 | desc += ')'; |
|---|
| 147 | return desc; |
|---|
| 148 | } |
|---|