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_FLINT_POSTLIST_H
00025 #define OM_HGUARD_FLINT_POSTLIST_H
00026
00027 #include <xapian/database.h>
00028
00029 #include "flint_types.h"
00030 #include "flint_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 FlintCursor;
00041 class FlintDatabase;
00042
00043 class FlintPostlistChunkReader;
00044 class FlintPostlistChunkWriter;
00045
00046 class FlintPostListTable : public FlintTable {
00047 public:
00060 FlintPostListTable(const string & path_, bool readonly_)
00061 : FlintTable("postlist", path_ + "/postlist.", readonly_) { }
00062
00064 void merge_changes(
00065 const map<string, map<Xapian::docid, pair<char, Xapian::termcount> > > & mod_plists,
00066 const map<Xapian::docid, Xapian::termcount> & doclens,
00067 const map<string, pair<Xapian::termcount_diff, Xapian::termcount_diff> > & freq_deltas);
00068
00069 Xapian::docid get_chunk(const string &tname,
00070 Xapian::docid did, bool adding,
00071 FlintPostlistChunkReader ** from, FlintPostlistChunkWriter **to);
00072
00074 static string make_key(const string & term, Xapian::docid did) {
00075 string key = F_pack_string_preserving_sort(term);
00076 key += F_pack_uint_preserving_sort(did);
00077 return key;
00078 }
00079
00081 static string make_key(const string & term) {
00082 return F_pack_string_preserving_sort(term);
00083 }
00084
00085 bool term_exists(const string & term) const {
00086 return key_exists(make_key(term));
00087 }
00088
00093 Xapian::doccount get_termfreq(const std::string & term) const;
00094
00099 Xapian::termcount get_collection_freq(const std::string & term) const;
00100 };
00101
00104 class FlintPostList : public LeafPostList {
00105 protected:
00110 Xapian::Internal::RefCntPtr<const FlintDatabase> this_db;
00111
00113 bool have_started;
00114
00116 FlintPositionList positionlist;
00117
00118 private:
00120 AutoPtr<FlintCursor> cursor;
00121
00123 bool is_last_chunk;
00124
00126 Xapian::docid first_did_in_chunk;
00127
00129 Xapian::docid last_did_in_chunk;
00130
00132 const char * pos;
00133
00135 const char * end;
00136
00138 Xapian::docid did;
00139
00141 flint_doclen_t doclength;
00142
00144 Xapian::termcount wdf;
00145
00147 bool is_at_end;
00148
00150 Xapian::doccount number_of_entries;
00151
00153 FlintPostList(const FlintPostList &);
00154
00156 void operator=(const FlintPostList &);
00157
00161 bool next_in_chunk();
00162
00168 void next_chunk();
00169
00177 bool current_chunk_contains(Xapian::docid desired_did);
00178
00190 void move_to_chunk_containing(Xapian::docid desired_did);
00191
00201 bool move_forward_in_chunk_to_at_least(Xapian::docid desired_did);
00202
00203 public:
00205 FlintPostList(Xapian::Internal::RefCntPtr<const FlintDatabase> this_db_,
00206 const string & term_);
00207
00209 ~FlintPostList();
00210
00215 Xapian::doccount get_termfreq() const { return number_of_entries; }
00216
00218 Xapian::docid get_docid() const { Assert(have_started); return did; }
00219
00221 Xapian::termcount get_doclength() const;
00222
00226 Xapian::termcount get_wdf() const { Assert(have_started); return wdf; }
00227
00230 PositionList *read_position_list();
00231
00234 PositionList * open_position_list() const;
00235
00237 PostList * next(Xapian::weight w_min);
00238
00240 PostList * skip_to(Xapian::docid desired_did, Xapian::weight w_min);
00241
00243 bool at_end() const { return is_at_end; }
00244
00246 std::string get_description() const;
00247
00249 static void read_number_of_entries(const char ** posptr,
00250 const char * end,
00251 Xapian::doccount * number_of_entries_ptr,
00252 Xapian::termcount * collection_freq_ptr);
00253 };
00254
00255 #endif