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_DATABASE_H
00025 #define OM_HGUARD_BRASS_DATABASE_H
00026
00027 #include "database.h"
00028 #include "brass_dbstats.h"
00029 #include "brass_inverter.h"
00030 #include "brass_positionlist.h"
00031 #include "brass_postlist.h"
00032 #include "brass_record.h"
00033 #include "brass_spelling.h"
00034 #include "brass_synonym.h"
00035 #include "brass_termlisttable.h"
00036 #include "brass_values.h"
00037 #include "brass_version.h"
00038 #include "../flint_lock.h"
00039 #include "brass_types.h"
00040 #include "valuestats.h"
00041
00042 #include <map>
00043
00044 class BrassTermList;
00045 class BrassAllDocsPostList;
00046 class RemoteConnection;
00047
00051 class BrassDatabase : public Xapian::Database::Internal {
00052 friend class BrassWritableDatabase;
00053 friend class BrassTermList;
00054 friend class BrassPostList;
00055 friend class BrassAllTermsList;
00056 friend class BrassAllDocsPostList;
00057 private:
00060 std::string db_dir;
00061
00064 bool readonly;
00065
00070 BrassVersion version_file;
00071
00078 mutable BrassPostListTable postlist_table;
00079
00082 BrassPositionListTable position_table;
00083
00086 BrassTermListTable termlist_table;
00087
00089 mutable BrassValueManager value_manager;
00090
00093 mutable BrassSynonymTable synonym_table;
00094
00097 mutable BrassSpellingTable spelling_table;
00098
00107 BrassRecordTable record_table;
00108
00110 FlintLock lock;
00111
00114 unsigned int max_changesets;
00115
00117 BrassDatabaseStats stats;
00118
00122 bool database_exists();
00123
00127 void create_and_open_tables(unsigned int blocksize);
00128
00134 void open_tables_consistent();
00135
00143 void get_database_write_lock(bool creating);
00144
00150 void open_tables(brass_revision_number_t revision);
00151
00157 brass_revision_number_t get_revision_number() const;
00158
00164 brass_revision_number_t get_next_revision_number() const;
00165
00176 void set_revision_number(brass_revision_number_t new_revision);
00177
00181 void reopen();
00182
00185 void close();
00186
00192 void modifications_failed(brass_revision_number_t old_revision,
00193 brass_revision_number_t new_revision,
00194 const std::string & msg);
00195
00204 void apply();
00205
00208 void cancel();
00209
00212 void send_whole_database(RemoteConnection & conn, double end_time);
00213
00216 void get_changeset_revisions(const string & path,
00217 brass_revision_number_t * startrev,
00218 brass_revision_number_t * endrev) const;
00219
00220 public:
00240 BrassDatabase(const string &db_dir_, int action = XAPIAN_DB_READONLY,
00241 unsigned int block_size = 0u);
00242
00243 ~BrassDatabase();
00244
00246 BrassCursor * get_postlist_cursor() const {
00247 return postlist_table.cursor_get();
00248 }
00249
00252 Xapian::doccount get_doccount() const;
00253 Xapian::docid get_lastdocid() const;
00254 totlen_t get_total_length() const;
00255 Xapian::doclength get_avlength() const;
00256 Xapian::termcount get_doclength(Xapian::docid did) const;
00257 Xapian::doccount get_termfreq(const string & tname) const;
00258 Xapian::termcount get_collection_freq(const string & tname) const;
00259 Xapian::doccount get_value_freq(Xapian::valueno slot) const;
00260 std::string get_value_lower_bound(Xapian::valueno slot) const;
00261 std::string get_value_upper_bound(Xapian::valueno slot) const;
00262 Xapian::termcount get_doclength_lower_bound() const;
00263 Xapian::termcount get_doclength_upper_bound() const;
00264 Xapian::termcount get_wdf_upper_bound(const string & term) const;
00265 bool term_exists(const string & tname) const;
00266 bool has_positions() const;
00267
00268 LeafPostList * open_post_list(const string & tname) const;
00269 ValueList * open_value_list(Xapian::valueno slot) const;
00270 Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const;
00271
00272 PositionList * open_position_list(Xapian::docid did, const string & term) const;
00273 TermList * open_term_list(Xapian::docid did) const;
00274 TermList * open_allterms(const string & prefix) const;
00275
00276 TermList * open_spelling_termlist(const string & word) const;
00277 TermList * open_spelling_wordlist() const;
00278 Xapian::doccount get_spelling_frequency(const string & word) const;
00279
00280 TermList * open_synonym_termlist(const string & term) const;
00281 TermList * open_synonym_keylist(const string & prefix) const;
00282
00283 string get_metadata(const string & key) const;
00284 TermList * open_metadata_keylist(const std::string &prefix) const;
00285 void write_changesets_to_fd(int fd,
00286 const string & start_revision,
00287 bool need_whole_db,
00288 Xapian::ReplicationInfo * info);
00289 string get_revision_info() const;
00290 string get_uuid() const;
00292
00293 };
00294
00297 class BrassWritableDatabase : public BrassDatabase {
00298 mutable Inverter inverter;
00299
00300 mutable map<Xapian::valueno, ValueStats> value_stats;
00301
00305 mutable Xapian::doccount change_count;
00306
00308 Xapian::doccount flush_threshold;
00309
00316 mutable Xapian::Document::Internal * modify_shortcut_document;
00317
00320 mutable Xapian::docid modify_shortcut_docid;
00321
00323 void flush_postlist_changes() const;
00324
00326 void close();
00327
00329 void apply();
00330
00332
00335 void commit();
00336
00338 void cancel();
00339
00340 Xapian::docid add_document(const Xapian::Document & document);
00341 Xapian::docid add_document_(Xapian::docid did, const Xapian::Document & document);
00342
00343
00344
00345
00346
00347 #ifndef _MSC_VER
00348 using Xapian::Database::Internal::delete_document;
00349 using Xapian::Database::Internal::replace_document;
00350 #endif
00351 void delete_document(Xapian::docid did);
00352 void replace_document(Xapian::docid did, const Xapian::Document & document);
00353
00354 Xapian::Document::Internal * open_document(Xapian::docid did,
00355 bool lazy) const;
00356
00358
00359 public:
00371 BrassWritableDatabase(const string &dir, int action, int block_size);
00372
00373 ~BrassWritableDatabase();
00374
00377 Xapian::termcount get_doclength(Xapian::docid did) const;
00378 Xapian::doccount get_termfreq(const string & tname) const;
00379 Xapian::termcount get_collection_freq(const string & tname) const;
00380 Xapian::doccount get_value_freq(Xapian::valueno slot) const;
00381 std::string get_value_lower_bound(Xapian::valueno slot) const;
00382 std::string get_value_upper_bound(Xapian::valueno slot) const;
00383 bool term_exists(const string & tname) const;
00384
00385 LeafPostList * open_post_list(const string & tname) const;
00386 ValueList * open_value_list(Xapian::valueno slot) const;
00387 TermList * open_allterms(const string & prefix) const;
00388
00389 void add_spelling(const string & word, Xapian::termcount freqinc) const;
00390 void remove_spelling(const string & word, Xapian::termcount freqdec) const;
00391 TermList * open_spelling_wordlist() const;
00392
00393 TermList * open_synonym_keylist(const string & prefix) const;
00394 void add_synonym(const string & word, const string & synonym) const;
00395 void remove_synonym(const string & word, const string & synonym) const;
00396 void clear_synonyms(const string & word) const;
00397
00398 void set_metadata(const string & key, const string & value);
00399 void invalidate_doc_object(Xapian::Document::Internal * obj) const;
00401 };
00402
00403 #endif