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 "noreturn.h"
00043
00044 #include <map>
00045
00046 class BrassTermList;
00047 class BrassAllDocsPostList;
00048 class RemoteConnection;
00049
00053 class BrassDatabase : public Xapian::Database::Internal {
00054 friend class BrassWritableDatabase;
00055 friend class BrassTermList;
00056 friend class BrassPostList;
00057 friend class BrassAllTermsList;
00058 friend class BrassAllDocsPostList;
00059 private:
00062 std::string db_dir;
00063
00066 bool readonly;
00067
00072 BrassVersion version_file;
00073
00080 mutable BrassPostListTable postlist_table;
00081
00084 BrassPositionListTable position_table;
00085
00088 BrassTermListTable termlist_table;
00089
00091 mutable BrassValueManager value_manager;
00092
00095 mutable BrassSynonymTable synonym_table;
00096
00099 mutable BrassSpellingTable spelling_table;
00100
00109 BrassRecordTable record_table;
00110
00112 FlintLock lock;
00113
00116 unsigned int max_changesets;
00117
00119 BrassDatabaseStats stats;
00120
00124 bool database_exists();
00125
00129 void create_and_open_tables(unsigned int blocksize);
00130
00136 void open_tables_consistent();
00137
00145 void get_database_write_lock(bool creating);
00146
00152 void open_tables(brass_revision_number_t revision);
00153
00159 brass_revision_number_t get_revision_number() const;
00160
00166 brass_revision_number_t get_next_revision_number() const;
00167
00178 void set_revision_number(brass_revision_number_t new_revision);
00179
00183 void reopen();
00184
00187 void close();
00188
00194 void modifications_failed(brass_revision_number_t old_revision,
00195 brass_revision_number_t new_revision,
00196 const std::string & msg);
00197
00206 void apply();
00207
00210 void cancel();
00211
00214 void send_whole_database(RemoteConnection & conn, double end_time);
00215
00218 void get_changeset_revisions(const string & path,
00219 brass_revision_number_t * startrev,
00220 brass_revision_number_t * endrev) const;
00221
00222 public:
00242 BrassDatabase(const string &db_dir_, int action = XAPIAN_DB_READONLY,
00243 unsigned int block_size = 0u);
00244
00245 ~BrassDatabase();
00246
00248 BrassCursor * get_postlist_cursor() const {
00249 return postlist_table.cursor_get();
00250 }
00251
00254 Xapian::doccount get_doccount() const;
00255 Xapian::docid get_lastdocid() const;
00256 totlen_t get_total_length() const;
00257 Xapian::doclength get_avlength() const;
00258 Xapian::termcount get_doclength(Xapian::docid did) const;
00259 Xapian::doccount get_termfreq(const string & tname) const;
00260 Xapian::termcount get_collection_freq(const string & tname) const;
00261 Xapian::doccount get_value_freq(Xapian::valueno slot) const;
00262 std::string get_value_lower_bound(Xapian::valueno slot) const;
00263 std::string get_value_upper_bound(Xapian::valueno slot) const;
00264 Xapian::termcount get_doclength_lower_bound() const;
00265 Xapian::termcount get_doclength_upper_bound() const;
00266 Xapian::termcount get_wdf_upper_bound(const string & term) const;
00267 bool term_exists(const string & tname) const;
00268 bool has_positions() const;
00269
00270 LeafPostList * open_post_list(const string & tname) const;
00271 ValueList * open_value_list(Xapian::valueno slot) const;
00272 Xapian::Document::Internal * open_document(Xapian::docid did, bool lazy) const;
00273
00274 PositionList * open_position_list(Xapian::docid did, const string & term) const;
00275 TermList * open_term_list(Xapian::docid did) const;
00276 TermList * open_allterms(const string & prefix) const;
00277
00278 TermList * open_spelling_termlist(const string & word) const;
00279 TermList * open_spelling_wordlist() const;
00280 Xapian::doccount get_spelling_frequency(const string & word) const;
00281
00282 TermList * open_synonym_termlist(const string & term) const;
00283 TermList * open_synonym_keylist(const string & prefix) const;
00284
00285 string get_metadata(const string & key) const;
00286 TermList * open_metadata_keylist(const std::string &prefix) const;
00287 void write_changesets_to_fd(int fd,
00288 const string & start_revision,
00289 bool need_whole_db,
00290 Xapian::ReplicationInfo * info);
00291 string get_revision_info() const;
00292 string get_uuid() const;
00294
00295 XAPIAN_NORETURN(void throw_termlist_table_close_exception() const);
00296 };
00297
00300 class BrassWritableDatabase : public BrassDatabase {
00301 mutable Inverter inverter;
00302
00303 mutable map<Xapian::valueno, ValueStats> value_stats;
00304
00308 mutable Xapian::doccount change_count;
00309
00311 Xapian::doccount flush_threshold;
00312
00319 mutable Xapian::Document::Internal * modify_shortcut_document;
00320
00323 mutable Xapian::docid modify_shortcut_docid;
00324
00326 void flush_postlist_changes() const;
00327
00329 void close();
00330
00332 void apply();
00333
00335
00338 void commit();
00339
00341 void cancel();
00342
00343 Xapian::docid add_document(const Xapian::Document & document);
00344 Xapian::docid add_document_(Xapian::docid did, const Xapian::Document & document);
00345
00346
00347
00348
00349
00350 #ifndef _MSC_VER
00351 using Xapian::Database::Internal::delete_document;
00352 using Xapian::Database::Internal::replace_document;
00353 #endif
00354 void delete_document(Xapian::docid did);
00355 void replace_document(Xapian::docid did, const Xapian::Document & document);
00356
00357 Xapian::Document::Internal * open_document(Xapian::docid did,
00358 bool lazy) const;
00359
00361
00362 public:
00374 BrassWritableDatabase(const string &dir, int action, int block_size);
00375
00376 ~BrassWritableDatabase();
00377
00380 Xapian::termcount get_doclength(Xapian::docid did) const;
00381 Xapian::doccount get_termfreq(const string & tname) const;
00382 Xapian::termcount get_collection_freq(const string & tname) const;
00383 Xapian::doccount get_value_freq(Xapian::valueno slot) const;
00384 std::string get_value_lower_bound(Xapian::valueno slot) const;
00385 std::string get_value_upper_bound(Xapian::valueno slot) const;
00386 bool term_exists(const string & tname) const;
00387
00388 LeafPostList * open_post_list(const string & tname) const;
00389 ValueList * open_value_list(Xapian::valueno slot) const;
00390 TermList * open_allterms(const string & prefix) const;
00391
00392 void add_spelling(const string & word, Xapian::termcount freqinc) const;
00393 void remove_spelling(const string & word, Xapian::termcount freqdec) const;
00394 TermList * open_spelling_wordlist() const;
00395
00396 TermList * open_synonym_keylist(const string & prefix) const;
00397 void add_synonym(const string & word, const string & synonym) const;
00398 void remove_synonym(const string & word, const string & synonym) const;
00399 void clear_synonyms(const string & word) const;
00400
00401 void set_metadata(const string & key, const string & value);
00402 void invalidate_doc_object(Xapian::Document::Internal * obj) const;
00404 };
00405
00406 #endif