backends/quartz/quartz_database.h

Go to the documentation of this file.
00001 /* quartz_database.h: C++ class definition for quartz database
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2002,2003,2004,2006,2007 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
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         // Stop the default implementation of delete_document(term) and
00274         // replace_document(term) from being hidden.  This isn't really
00275         // a problem as we only try to call them through the base class
00276         // (where they aren't hidden) but some compilers generate a warning
00277         // about the hiding.
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 /* OM_HGUARD_QUARTZ_DATABASE_H */

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.