# 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,2008,2009 Olly Betts
    00007  * Copyright 2006,2008 Lemur Consulting Ltd
    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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
    00022  * USA
    00023  */
    00024
    00025 #ifndef XAPIAN_INCLUDED_DATABASE_H
    00026 #define XAPIAN_INCLUDED_DATABASE_H
    00027
    00028 #include <string>
    00029 #include <vector>
    00030
    00031 #include <xapian/base.h>
    00032 #include <xapian/types.h>
    00033 #include <xapian/positioniterator.h>
    00034 #include <xapian/postingiterator.h>
    00035 #include <xapian/termiterator.h>
    00036 #include <xapian/visibility.h>
    00037
    00039 namespace Xapian {
    00040
    00041 class Document;
    00042
    00057 class XAPIAN_VISIBILITY_DEFAULT Database {
    00058     public:
    00059         class Internal;
    00061         std::vector<Xapian::Internal::RefCntPtr<Internal> > internal;
    00062
    00068         void add_database(const Database & database);
    00069
    00072         Database();
    00073
    00079         explicit Database(const std::string &path);
    00080
    00083         explicit Database(Internal *internal);
    00084
    00090         virtual ~Database();
    00091
    00095         Database(const Database &other);
    00096
    00100         void operator=(const Database &other);
    00101
    00107         void reopen();
    00108
    00110         virtual std::string get_description() const;
    00111
    00120         PostingIterator postlist_begin(const std::string &tname) const;
    00121
    00124         PostingIterator postlist_end(const std::string &) const {
    00125             return PostingIterator(NULL);
    00126         }
    00127
    00131         TermIterator termlist_begin(Xapian::docid did) const;
    00132
    00135         TermIterator termlist_end(Xapian::docid) const {
    00136             return TermIterator(NULL);
    00137         }
    00138
    00140         bool has_positions() const;
    00141
    00145         PositionIterator positionlist_begin(Xapian::docid did, const std::string &tname) const;
    00146
    00149         PositionIterator positionlist_end(Xapian::docid, const std::string &) const {
    00150             return PositionIterator(NULL);
    00151         }
    00152
    00155         TermIterator allterms_begin() const;
    00156
    00159         TermIterator allterms_end() const {
    00160             return TermIterator(NULL);
    00161         }
    00162
    00174         TermIterator allterms_begin(const std::string & prefix) const;
    00175
    00178         TermIterator allterms_end(const std::string &) const {
    00179             return TermIterator(NULL);
    00180         }
    00181
    00183         Xapian::doccount get_doccount() const;
    00184
    00186         Xapian::docid get_lastdocid() const;
    00187
    00189         Xapian::doclength get_avlength() const;
    00190
    00192         Xapian::doccount get_termfreq(const std::string & tname) const;
    00193
    00200         bool term_exists(const std::string & tname) const;
    00201
    00211         Xapian::termcount get_collection_freq(const std::string & tname) const;
    00212
    00215         Xapian::doclength get_doclength(Xapian::docid did) const;
    00216
    00220         void keep_alive();
    00221
    00234         Xapian::Document get_document(Xapian::docid did) const;
    00235
    00244         std::string get_spelling_suggestion(const std::string &word,
    00245                                             unsigned max_edit_distance = 2) const;
    00246
    00254         Xapian::TermIterator spellings_begin() const;
    00255
    00257         Xapian::TermIterator spellings_end() const {
    00258             return Xapian::TermIterator(NULL);
    00259         }
    00260
    00265         Xapian::TermIterator synonyms_begin(const std::string &term) const;
    00266
    00268         Xapian::TermIterator synonyms_end(const std::string &) const {
    00269             return Xapian::TermIterator(NULL);
    00270         }
    00271
    00277         Xapian::TermIterator synonym_keys_begin(const std::string &prefix = "") const;
    00278
    00280         Xapian::TermIterator synonym_keys_end(const std::string & = "") const {
    00281             return Xapian::TermIterator(NULL);
    00282         }
    00283
    00308         std::string get_metadata(const std::string & key) const;
    00309
    00328         Xapian::TermIterator metadata_keys_begin(const std::string &prefix = "") const;
    00329
    00331         Xapian::TermIterator metadata_keys_end(const std::string & = "") const {
    00332             return Xapian::TermIterator(NULL);
    00333         }
    00334 };
    00335
    00338 class XAPIAN_VISIBILITY_DEFAULT WritableDatabase : public Database {
    00339     public:
    00346         virtual ~WritableDatabase();
    00347
    00350         WritableDatabase();
    00351
    00374         WritableDatabase(const std::string &path, int action);
    00375
    00378         explicit WritableDatabase(Database::Internal *internal);
    00379
    00383         WritableDatabase(const WritableDatabase &other);
    00384
    00392         void operator=(const WritableDatabase &other);
    00393
    00431         void flush();
    00432
    00472         void begin_transaction(bool flushed=true);
    00473
    00499         void commit_transaction();
    00500
    00519         void cancel_transaction();
    00520
    00549         Xapian::docid add_document(const Xapian::Document & document);
    00550
    00572         void delete_document(Xapian::docid did);
    00573
    00593         void delete_document(const std::string & unique_term);
    00594
    00626         void replace_document(Xapian::docid did,
    00627                               const Xapian::Document & document);
    00628
    00662         Xapian::docid replace_document(const std::string & unique_term,
    00663                                        const Xapian::Document & document);
    00664
    00672         void add_spelling(const std::string & word,
    00673                           Xapian::termcount freqinc = 1) const;
    00674
    00683         void remove_spelling(const std::string & word,
    00684                              Xapian::termcount freqdec = 1) const;
    00685
    00691         void add_synonym(const std::string & term,
    00692                          const std::string & synonym) const;
    00693
    00698         void remove_synonym(const std::string & term,
    00699                             const std::string & synonym) const;
    00700
    00705         void clear_synonyms(const std::string & term) const;
    00706
    00751         void set_metadata(const std::string & key, const std::string & value);
    00752
    00754         std::string get_description() const;
    00755 };
    00756
    00758 const int DB_CREATE_OR_OPEN = 1;
    00760 const int DB_CREATE = 2;
    00762 const int DB_CREATE_OR_OVERWRITE = 3;
    00764 const int DB_OPEN = 4;
    00765 // Can't see any sensible use for this one
    00766 // const int DB_OVERWRITE = XXX;
    00767
    00768 }
    00769
    00770 #endif /* XAPIAN_INCLUDED_DATABASE_H */