00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef OM_HGUARD_CHERT_POSTLIST_H
00025 #define OM_HGUARD_CHERT_POSTLIST_H
00026
00027 #include <xapian/database.h>
00028
00029 #include "chert_types.h"
00030 #include "chert_positionlist.h"
00031 #include "leafpostlist.h"
00032 #include "omassert.h"
00033
00034 #include "autoptr.h"
00035 #include <map>
00036 #include <string>
00037
00038 using namespace std;
00039
00040 class ChertCursor;
00041 class ChertDatabase;
00042
00043 namespace Chert {
00044 class PostlistChunkReader;
00045 class PostlistChunkWriter;
00046 }
00047
00048 class ChertPostList;
00049
00050 class ChertPostListTable : public ChertTable {
00052 mutable AutoPtr<ChertPostList> doclen_pl;
00053
00054 public:
00067 ChertPostListTable(const string & path_, bool readonly_)
00068 : ChertTable("postlist", path_ + "/postlist.", readonly_),
00069 doclen_pl()
00070 { }
00071
00072 bool open(chert_revision_number_t revno) {
00073 doclen_pl.reset(0);
00074 return ChertTable::open(revno);
00075 }
00076
00078 void merge_changes(
00079 const map<string, map<Xapian::docid, pair<char, Xapian::termcount> > > & mod_plists,
00080 const map<Xapian::docid, Xapian::termcount> & doclens,
00081 const map<string, pair<Xapian::termcount_diff, Xapian::termcount_diff> > & freq_deltas);
00082
00083 Xapian::docid get_chunk(const string &tname,
00084 Xapian::docid did, bool adding,
00085 Chert::PostlistChunkReader ** from,
00086 Chert::PostlistChunkWriter **to);
00087
00089 static string make_key(const string & term, Xapian::docid did) {
00090 return pack_chert_postlist_key(term, did);
00091 }
00092
00094 static string make_key(const string & term) {
00095 return pack_chert_postlist_key(term);
00096 }
00097
00098 bool term_exists(const string & term) const {
00099 return key_exists(make_key(term));
00100 }
00101
00106 Xapian::doccount get_termfreq(const std::string & term) const;
00107
00112 Xapian::termcount get_collection_freq(const std::string & term) const;
00113
00115 Xapian::termcount get_doclength(Xapian::docid did,
00116 Xapian::Internal::RefCntPtr<const ChertDatabase> db) const;
00117
00119 bool document_exists(Xapian::docid did,
00120 Xapian::Internal::RefCntPtr<const ChertDatabase> db) const;
00121 };
00122
00125 class ChertPostList : public LeafPostList {
00126 protected:
00131 Xapian::Internal::RefCntPtr<const ChertDatabase> this_db;
00132
00134 ChertPositionList positionlist;
00135
00137 bool have_started;
00138
00139 private:
00141 bool is_last_chunk;
00142
00144 bool is_at_end;
00145
00147 AutoPtr<ChertCursor> cursor;
00148
00150 Xapian::docid first_did_in_chunk;
00151
00153 Xapian::docid last_did_in_chunk;
00154
00156 const char * pos;
00157
00159 const char * end;
00160
00162 Xapian::docid did;
00163
00165 Xapian::termcount wdf;
00166
00168 Xapian::doccount number_of_entries;
00169
00171 ChertPostList(const ChertPostList &);
00172
00174 void operator=(const ChertPostList &);
00175
00179 bool next_in_chunk();
00180
00186 void next_chunk();
00187
00195 bool current_chunk_contains(Xapian::docid desired_did);
00196
00208 void move_to_chunk_containing(Xapian::docid desired_did);
00209
00219 bool move_forward_in_chunk_to_at_least(Xapian::docid desired_did);
00220
00221 public:
00223 ChertPostList(Xapian::Internal::RefCntPtr<const ChertDatabase> this_db_,
00224 const string & term,
00225 bool keep_reference);
00226
00228 ~ChertPostList();
00229
00234 bool jump_to(Xapian::docid desired_did);
00235
00240 Xapian::doccount get_termfreq() const { return number_of_entries; }
00241
00243 Xapian::docid get_docid() const { Assert(have_started); return did; }
00244
00246 Xapian::termcount get_doclength() const;
00247
00251 Xapian::termcount get_wdf() const { Assert(have_started); return wdf; }
00252
00255 PositionList *read_position_list();
00256
00259 PositionList * open_position_list() const;
00260
00262 PostList * next(Xapian::weight w_min);
00263
00265 PostList * skip_to(Xapian::docid desired_did, Xapian::weight w_min);
00266
00268 bool at_end() const { return is_at_end; }
00269
00271 std::string get_description() const;
00272
00274 static void read_number_of_entries(const char ** posptr,
00275 const char * end,
00276 Xapian::doccount * number_of_entries_ptr,
00277 Xapian::termcount * collection_freq_ptr);
00278 };
00279
00280 #endif