00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef OM_HGUARD_QUARTZ_DATABASE_H
00024 #define OM_HGUARD_QUARTZ_DATABASE_H
00025
00026 #include <xapian/visibility.h>
00027
00028 #include "database.h"
00029 #include "quartz_log.h"
00030 #include "quartz_metafile.h"
00031 #include "quartz_positionlist.h"
00032 #include "quartz_postlist.h"
00033 #include "quartz_record.h"
00034 #include "quartz_termlist.h"
00035 #include "quartz_values.h"
00036
00037 class QuartzTermList;
00038
00039 #include "quartz_types.h"
00040
00041 #include <map>
00042
00043 const int OM_DB_READONLY = 0;
00044
00048 class XAPIAN_VISIBILITY_DEFAULT QuartzDatabase : public Xapian::Database::Internal {
00049 friend class QuartzWritableDatabase;
00050 friend class QuartzTermList;
00051 private:
00054 std::string db_dir;
00055
00058 bool readonly;
00059
00064 QuartzMetaFile metafile;
00065
00072 QuartzPostListTable postlist_table;
00073
00076 QuartzPositionListTable positionlist_table;
00077
00080 QuartzTermListTable termlist_table;
00081
00084 QuartzValueTable value_table;
00085
00094 QuartzRecordTable record_table;
00095
00098 QuartzLog log;
00099
00103 bool database_exists();
00104
00108 void create_and_open_tables(unsigned int blocksize);
00109
00115 void open_tables_consistent();
00116
00120 void get_database_write_lock();
00121
00124 void release_database_write_lock();
00125
00131 void open_tables(quartz_revision_number_t revision);
00132
00138 quartz_revision_number_t get_revision_number() const;
00139
00145 quartz_revision_number_t get_next_revision_number() const;
00146
00157 void set_revision_number(quartz_revision_number_t new_revision);
00158
00162 virtual void reopen();
00163
00174 void apply();
00175
00178 void cancel();
00179
00180 public:
00201 QuartzDatabase(const string &db_dir_, int action = OM_DB_READONLY,
00202 unsigned int block_size = 0u);
00203
00204 ~QuartzDatabase();
00205
00209 Xapian::doccount get_doccount() const;
00210 Xapian::docid get_lastdocid() const;
00211 Xapian::doclength get_avlength() const;
00212 Xapian::doclength get_doclength(Xapian::docid did) const;
00213 Xapian::doccount get_termfreq(const string & tname) const;
00214 Xapian::termcount get_collection_freq(const string & tname) const;
00215 bool term_exists(const string & tname) const;
00216 bool has_positions() const;
00217
00218 LeafPostList * open_post_list(const string & tname) const;
00219 TermList * open_term_list(Xapian::docid did) const;
00220 Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy = false) const;
00221 PositionList * open_position_list(Xapian::docid did,
00222 const string & tname) const;
00223 TermList * open_allterms(const string & prefix) const;
00225 };
00226
00229 class XAPIAN_VISIBILITY_DEFAULT QuartzWritableDatabase : public Xapian::Database::Internal {
00230 private:
00232 mutable map<string, pair<Xapian::termcount_diff, Xapian::termcount_diff> >
00233 freq_deltas;
00234
00236 mutable map<Xapian::docid, Xapian::termcount> doclens;
00237
00239 mutable map<string, map<Xapian::docid,
00240 pair<char, Xapian::termcount> > > mod_plists;
00241
00244 mutable QuartzDatabase database_ro;
00245
00248 mutable quartz_totlen_t total_length;
00249
00252 mutable Xapian::docid lastdocid;
00253
00257 mutable Xapian::doccount changes_made;
00258
00259 static size_t flush_threshold;
00260
00262
00264 void flush();
00265
00266 void do_flush_const() const;
00267
00269 void cancel();
00270
00271 virtual Xapian::docid add_document(const Xapian::Document & document);
00272 Xapian::docid add_document_(Xapian::docid did, const Xapian::Document & document);
00273
00274
00275
00276
00277
00278 #if (!defined __GNUC__ && !defined _MSC_VER) || __GNUC__ > 2
00279 using Xapian::Database::Internal::delete_document;
00280 using Xapian::Database::Internal::replace_document;
00281 #endif
00282 virtual void delete_document(Xapian::docid did);
00283 virtual void replace_document(Xapian::docid did,
00284 const Xapian::Document & document);
00286
00287 public:
00299 QuartzWritableDatabase(const string &dir, int action, int block_size);
00300
00301 ~QuartzWritableDatabase();
00302
00306 Xapian::doccount get_doccount() const;
00307 Xapian::docid get_lastdocid() const;
00308 Xapian::doclength get_avlength() const;
00309 Xapian::doclength get_doclength(Xapian::docid did) const;
00310 Xapian::doccount get_termfreq(const string & tname) const;
00311 Xapian::termcount get_collection_freq(const string & tname) const;
00312 bool term_exists(const string & tname) const;
00313 bool has_positions() const;
00314
00315 LeafPostList * open_post_list(const string & tname) const;
00316 TermList * open_term_list(Xapian::docid did) const;
00317 Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy = false) const;
00318 PositionList * open_position_list(Xapian::docid did,
00319 const string & tname) const;
00320 TermList * open_allterms(const string & prefix) const;
00322 };
00323
00324 #endif