00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_CHERT_SYNONYM_H
00022 #define XAPIAN_INCLUDED_CHERT_SYNONYM_H
00023
00024 #include <xapian/types.h>
00025
00026 #include "alltermslist.h"
00027 #include "database.h"
00028 #include "chert_lazytable.h"
00029 #include "termlist.h"
00030
00031 #include <set>
00032 #include <string>
00033
00034 class ChertSynonymTable : public ChertLazyTable {
00036 mutable std::string last_term;
00037
00039 mutable std::set<std::string> last_synonyms;
00040
00041 public:
00050 ChertSynonymTable(const std::string & dbdir, bool readonly)
00051 : ChertLazyTable("synonym", dbdir + "/synonym.", readonly,
00052 Z_DEFAULT_STRATEGY) { }
00053
00054
00055 void merge_changes();
00056
00057
00058 void discard_changes() {
00059 last_term.resize(0);
00060 last_synonyms.clear();
00061 }
00062
00067 void add_synonym(const std::string & term, const std::string & synonym);
00068
00073 void remove_synonym(const std::string & term, const std::string & synonym);
00074
00079 void clear_synonyms(const std::string & term);
00080
00085 TermList * open_termlist(const std::string & term);
00086
00094 bool is_modified() const {
00095 return !last_term.empty() || ChertTable::is_modified();
00096 }
00097
00098 void flush_db() {
00099 merge_changes();
00100 ChertTable::flush_db();
00101 }
00102
00103 void cancel() {
00104 discard_changes();
00105 ChertTable::cancel();
00106 }
00107
00108
00109 };
00110
00111 class ChertCursor;
00112
00113 class ChertSynonymTermList : public AllTermsList {
00115 ChertSynonymTermList(const ChertSynonymTermList &);
00116
00118 void operator=(const ChertSynonymTermList &);
00119
00121 Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database;
00122
00126 ChertCursor * cursor;
00127
00129 string prefix;
00130
00131 public:
00132 ChertSynonymTermList(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
00133 ChertCursor * cursor_,
00134 const string & prefix_)
00135 : database(database_), cursor(cursor_), prefix(prefix_)
00136 {
00137
00138
00139
00140 if (prefix.empty()) {
00141 cursor->find_entry(string());
00142 } else {
00143
00144 cursor->find_entry_lt(prefix);
00145 }
00146 }
00147
00149 ~ChertSynonymTermList();
00150
00156 string get_termname() const;
00157
00159 Xapian::doccount get_termfreq() const;
00160
00162 Xapian::termcount get_collection_freq() const;
00163
00165 TermList * next();
00166
00168 TermList * skip_to(const string &tname);
00169
00171 bool at_end() const;
00172 };
00173
00174 #endif // XAPIAN_INCLUDED_CHERT_SYNONYM_H