# include/xapian/database.h

Go to the documentation of this file.

    00001
    00004 /* ----START-LICENCE----
    00005  * Copyright 1999,2000,2001 BrightStation PLC
    00006  * Copyright 2002 Ananova Ltd
    00007  * Copyright 2002,2003,2004,2005 Olly Betts
    00008  *
    00009  * This program is free software; you can redistribute it and/or
    00010  * modify it under the terms of the GNU General Public License as
    00011  * published by the Free Software Foundation; either version 2 of the
    00012  * License, or (at your option) any later version.
    00013  *
    00014  * This program is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017  * GNU General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU General Public License
    00020  * along with this program; if not, write to the Free Software
    00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    00022  * USA
    00023  * -----END-LICENCE-----
    00024  */
    00025
    00026 #ifndef XAPIAN_INCLUDED_DATABASE_H
    00027 #define XAPIAN_INCLUDED_DATABASE_H
    00028
    00029 #include <string>
    00030 #include <vector>
    00031
    00032 #include <xapian/base.h>
    00033 #include <xapian/types.h>
    00034 #include <xapian/positioniterator.h>
    00035 #include <xapian/postingiterator.h>
    00036 #include <xapian/termiterator.h>
    00037
    00039 namespace Xapian {
    00040
    00041 class Document;
    00042
    00053 class Database {
    00054     public:
    00060         void add_database(const Database & database);
    00061
    00062     public:
    00063         class Internal;
    00065         std::vector<Xapian::Internal::RefCntPtr<Internal> > internal;
    00066
    00067     public:
    00070         Database();
    00071
    00077         Database(const std::string &path);
    00078
    00081         explicit Database(Internal *internal);
    00082
    00088         virtual ~Database();
    00089
    00093         Database(const Database &other);
    00094
    00098         void operator=(const Database &other);
    00099
    00105         void reopen();
    00106
    00111         virtual std::string get_description() const;
    00112
    00116         PostingIterator postlist_begin(const std::string &tname) const;
    00117
    00120         PostingIterator postlist_end(const std::string &) const {
    00121             return PostingIterator(NULL);
    00122         }
    00123
    00127         TermIterator termlist_begin(Xapian::docid did) const;
    00128
    00131         TermIterator termlist_end(Xapian::docid) const {
    00132             return TermIterator(NULL);
    00133         }
    00134
    00138         PositionIterator positionlist_begin(Xapian::docid did, const std::string &tname) const;
    00139
    00142         PositionIterator positionlist_end(Xapian::docid, const std::string &) const {
    00143             return PositionIterator(NULL);
    00144         }
    00145
    00148         TermIterator allterms_begin() const;
    00149
    00152         TermIterator allterms_end() const {
    00153             return TermIterator(NULL);
    00154         }
    00155
    00157         Xapian::doccount get_doccount() const;
    00158
    00160         Xapian::docid get_lastdocid() const;
    00161
    00163         Xapian::doclength get_avlength() const;
    00164
    00166         Xapian::doccount get_termfreq(const std::string & tname) const;
    00167
    00174         bool term_exists(const std::string & tname) const;
    00175
    00185         Xapian::termcount get_collection_freq(const std::string & tname) const;
    00186
    00189         Xapian::doclength get_doclength(Xapian::docid did) const;
    00190
    00194         void keep_alive();
    00195
    00208         Xapian::Document get_document(Xapian::docid did) const;
    00209 };
    00210
    00213 class WritableDatabase : public Database {
    00214     public:
    00221         virtual ~WritableDatabase();
    00222
    00225         WritableDatabase();
    00226
    00243         WritableDatabase(const std::string &path, int action);
    00244
    00247         explicit WritableDatabase(Database::Internal *internal);
    00248
    00252         WritableDatabase(const WritableDatabase &other);
    00253
    00261         void operator=(const WritableDatabase &other);
    00262
    00302         void flush();
    00303
    00323         void begin_transaction();
    00324
    00351         void commit_transaction();
    00352
    00371         void cancel_transaction();
    00372
    00396         Xapian::docid add_document(const Xapian::Document & document);
    00397
    00419         void delete_document(Xapian::docid did);
    00420
    00438         void delete_document(const std::string & unique_term);
    00439
    00461         void replace_document(Xapian::docid did,
    00462                               const Xapian::Document & document);
    00463
    00495         Xapian::docid replace_document(const std::string & unique_term,
    00496                                        const Xapian::Document & document);
    00497
    00502         std::string get_description() const;
    00503 };
    00504
    00505 const int DB_CREATE_OR_OPEN = 1;
    00506 const int DB_CREATE = 2;
    00507 const int DB_CREATE_OR_OVERWRITE = 3;
    00508 const int DB_OPEN = 4;
    00509 // Can't see any sensible use for this one
    00510 // const int DB_OVERWRITE = XXX;
    00511
    00512 }
    00513
    00514 #endif /* XAPIAN_INCLUDED_DATABASE_H */