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_BRASS_POSTLIST_H
00025 #define OM_HGUARD_BRASS_POSTLIST_H
00026
00027 #include <xapian/database.h>
00028
00029 #include "brass_inverter.h"
00030 #include "brass_types.h"
00031 #include "brass_positionlist.h"
00032 #include "leafpostlist.h"
00033 #include "omassert.h"
00034
00035 #include "autoptr.h"
00036 #include <map>
00037 #include <string>
00038
00039 using namespace std;
00040
00041 class BrassCursor;
00042 class BrassDatabase;
00043
00044 namespace Brass {
00045 class PostlistChunkReader;
00046 class PostlistChunkWriter;
00047 }
00048
00049 class BrassPostList;
00050
00051 class BrassPostListTable : public BrassTable {
00053 mutable AutoPtr<BrassPostList> doclen_pl;
00054
00055 public:
00068 BrassPostListTable(const string & path_, bool readonly_)
00069 : BrassTable("postlist", path_ + "/postlist.", readonly_),
00070 doclen_pl()
00071 { }
00072
00073 bool open(brass_revision_number_t revno) {
00074 doclen_pl.reset(0);
00075 return BrassTable::open(revno);
00076 }
00077
00079 void merge_changes(const string &term, const Inverter::PostingChanges & changes);
00080
00082 void merge_doclen_changes(const map<Xapian::docid, Xapian::termcount> & doclens);
00083
00084 Xapian::docid get_chunk(const string &tname,
00085 Xapian::docid did, bool adding,
00086 Brass::PostlistChunkReader ** from,
00087 Brass::PostlistChunkWriter **to);
00088
00090 static string make_key(const string & term, Xapian::docid did) {
00091 return pack_brass_postlist_key(term, did);
00092 }
00093
00095 static string make_key(const string & term) {
00096 return pack_brass_postlist_key(term);
00097 }
00098
00099 bool term_exists(const string & term) const {
00100 return key_exists(make_key(term));
00101 }
00102
00107 Xapian::doccount get_termfreq(const std::string & term) const;
00108
00113 Xapian::termcount get_collection_freq(const std::string & term) const;
00114
00116 Xapian::termcount get_doclength(Xapian::docid did,
00117 Xapian::Internal::RefCntPtr<const BrassDatabase> db) const;
00118
00120 bool document_exists(Xapian::docid did,
00121 Xapian::Internal::RefCntPtr<const BrassDatabase> db) const;
00122 };
00123
00126 class BrassPostList : public LeafPostList {
00127 protected:
00132 Xapian::Internal::RefCntPtr<const BrassDatabase> this_db;
00133
00135 BrassPositionList positionlist;
00136
00138 bool have_started;
00139
00140 private:
00142 bool is_last_chunk;
00143
00145 bool is_at_end;
00146
00148 AutoPtr<BrassCursor> cursor;
00149
00151 Xapian::docid first_did_in_chunk;
00152
00154 Xapian::docid last_did_in_chunk;
00155
00157 const char * pos;
00158
00160 const char * end;
00161
00163 Xapian::docid did;
00164
00166 Xapian::termcount wdf;
00167
00169 Xapian::doccount number_of_entries;
00170
00172 BrassPostList(const BrassPostList &);
00173
00175 void operator=(const BrassPostList &);
00176
00180 bool next_in_chunk();
00181
00187 void next_chunk();
00188
00196 bool current_chunk_contains(Xapian::docid desired_did);
00197
00209 void move_to_chunk_containing(Xapian::docid desired_did);
00210
00220 bool move_forward_in_chunk_to_at_least(Xapian::docid desired_did);
00221
00222 public:
00224 BrassPostList(Xapian::Internal::RefCntPtr<const BrassDatabase> this_db_,
00225 const string & term,
00226 bool keep_reference);
00227
00229 ~BrassPostList();
00230
00235 bool jump_to(Xapian::docid desired_did);
00236
00241 Xapian::doccount get_termfreq() const { return number_of_entries; }
00242
00244 Xapian::docid get_docid() const { Assert(have_started); return did; }
00245
00247 Xapian::termcount get_doclength() const;
00248
00252 Xapian::termcount get_wdf() const { Assert(have_started); return wdf; }
00253
00256 PositionList *read_position_list();
00257
00260 PositionList * open_position_list() const;
00261
00263 PostList * next(Xapian::weight w_min);
00264
00266 PostList * skip_to(Xapian::docid desired_did, Xapian::weight w_min);
00267
00269 bool at_end() const { return is_at_end; }
00270
00272 std::string get_description() const;
00273
00275 static void read_number_of_entries(const char ** posptr,
00276 const char * end,
00277 Xapian::doccount * number_of_entries_ptr,
00278 Xapian::termcount * collection_freq_ptr);
00279 };
00280
00281 #endif