include/xapian/database.h

Go to the documentation of this file.
00001 
00004 /* Copyright 1999,2000,2001 BrightStation PLC
00005  * Copyright 2002 Ananova Ltd
00006  * Copyright 2002,2003,2004,2005,2006,2007 Olly Betts
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00021  * USA
00022  */
00023 
00024 #ifndef XAPIAN_INCLUDED_DATABASE_H
00025 #define XAPIAN_INCLUDED_DATABASE_H
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 #include <xapian/base.h>
00031 #include <xapian/types.h>
00032 #include <xapian/positioniterator.h>
00033 #include <xapian/postingiterator.h>
00034 #include <xapian/termiterator.h>
00035 
00037 namespace Xapian {
00038 
00039 class Document;
00040 
00051 class Database {
00052     public:
00053         class Internal;
00055         std::vector<Xapian::Internal::RefCntPtr<Internal> > internal;
00056 
00062         void add_database(const Database & database);
00063 
00066         Database();
00067 
00073         Database(const std::string &path);
00074 
00077         explicit Database(Internal *internal);
00078 
00084         virtual ~Database();
00085 
00089         Database(const Database &other);
00090 
00094         void operator=(const Database &other);
00095 
00101         void reopen();
00102 
00107         virtual std::string get_description() const;
00108 
00112         PostingIterator postlist_begin(const std::string &tname) const;
00113 
00116         PostingIterator postlist_end(const std::string &) const {
00117             return PostingIterator(NULL);
00118         }
00119 
00123         TermIterator termlist_begin(Xapian::docid did) const;
00124 
00127         TermIterator termlist_end(Xapian::docid) const {
00128             return TermIterator(NULL);
00129         }
00130 
00132         bool has_positions() const;
00133 
00137         PositionIterator positionlist_begin(Xapian::docid did, const std::string &tname) const;
00138 
00141         PositionIterator positionlist_end(Xapian::docid, const std::string &) const {
00142             return PositionIterator(NULL);
00143         }
00144 
00147         TermIterator allterms_begin() const;
00148 
00151         TermIterator allterms_end() const {
00152             return TermIterator(NULL);
00153         }
00154 
00156         Xapian::doccount get_doccount() const;
00157 
00159         Xapian::docid get_lastdocid() const;
00160 
00162         Xapian::doclength get_avlength() const;
00163 
00165         Xapian::doccount get_termfreq(const std::string & tname) const;
00166 
00173         bool term_exists(const std::string & tname) const;
00174 
00184         Xapian::termcount get_collection_freq(const std::string & tname) const;
00185 
00188         Xapian::doclength get_doclength(Xapian::docid did) const;
00189 
00193         void keep_alive();
00194 
00207         Xapian::Document get_document(Xapian::docid did) const;
00208 };
00209 
00212 class WritableDatabase : public Database {
00213     public:
00220         virtual ~WritableDatabase();
00221 
00224         WritableDatabase();
00225 
00242         WritableDatabase(const std::string &path, int action);
00243 
00246         explicit WritableDatabase(Database::Internal *internal);
00247 
00251         WritableDatabase(const WritableDatabase &other);
00252 
00260         void operator=(const WritableDatabase &other);
00261 
00298         void flush();
00299 
00339         void begin_transaction(bool flushed=true);
00340 
00366         void commit_transaction();
00367 
00386         void cancel_transaction();
00387 
00416         Xapian::docid add_document(const Xapian::Document & document);
00417 
00439         void delete_document(Xapian::docid did);
00440 
00458         void delete_document(const std::string & unique_term);
00459 
00483         void replace_document(Xapian::docid did,
00484                               const Xapian::Document & document);
00485 
00517         Xapian::docid replace_document(const std::string & unique_term,
00518                                        const Xapian::Document & document);
00519 
00524         std::string get_description() const;
00525 };
00526 
00528 const int DB_CREATE_OR_OPEN = 1;
00530 const int DB_CREATE = 2;
00532 const int DB_CREATE_OR_OVERWRITE = 3;
00534 const int DB_OPEN = 4;
00535 // Can't see any sensible use for this one
00536 // const int DB_OVERWRITE = XXX;
00537 
00538 }
00539 
00540 #endif /* XAPIAN_INCLUDED_DATABASE_H */

Documentation for Xapian (version 0.9.10).
Generated on 6 Mar 2007 by Doxygen 1.4.6.