00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_FLINT_SYNONYM_H
00022 #define XAPIAN_INCLUDED_FLINT_SYNONYM_H
00023
00024 #include <xapian/types.h>
00025
00026 #include "alltermslist.h"
00027 #include "database.h"
00028 #include "flint_table.h"
00029 #include "termlist.h"
00030
00031 #include <set>
00032 #include <string>
00033
00034 class FlintSynonymTable : public FlintTable {
00036 mutable std::string last_term;
00037
00039 mutable std::set<std::string> last_synonyms;
00040
00041 public:
00050 FlintSynonymTable(const std::string & dbdir, bool readonly)
00051 : FlintTable("synonym", dbdir + "/synonym.", readonly, Z_DEFAULT_STRATEGY, true) { }
00052
00053
00054 void merge_changes();
00055
00056
00057 void discard_changes() {
00058 last_term.resize(0);
00059 last_synonyms.clear();
00060 }
00061
00066 void add_synonym(const std::string & term, const std::string & synonym);
00067
00072 void remove_synonym(const std::string & term, const std::string & synonym);
00073
00078 void clear_synonyms(const std::string & term);
00079
00084 TermList * open_termlist(const std::string & term);
00085
00093 bool is_modified() const {
00094 return !last_term.empty() || FlintTable::is_modified();
00095 }
00096
00097 void create_and_open(unsigned int blocksize) {
00098
00099
00100 FlintTable::erase();
00101 FlintTable::set_block_size(blocksize);
00102 }
00103
00104 void flush_db() {
00105 merge_changes();
00106 FlintTable::flush_db();
00107 }
00108
00109 void cancel() {
00110 discard_changes();
00111 FlintTable::cancel();
00112 }
00113
00114
00115 };
00116
00117 class FlintCursor;
00118
00119 class FlintSynonymTermList : public AllTermsList {
00121 FlintSynonymTermList(const FlintSynonymTermList &);
00122
00124 void operator=(const FlintSynonymTermList &);
00125
00127 Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database;
00128
00132 FlintCursor * cursor;
00133
00135 string prefix;
00136
00137 public:
00138 FlintSynonymTermList(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
00139 FlintCursor * cursor_,
00140 const string & prefix_)
00141 : database(database_), cursor(cursor_), prefix(prefix_)
00142 {
00143
00144
00145
00146 if (prefix.empty()) {
00147 cursor->find_entry(string());
00148 } else {
00149
00150 cursor->find_entry_lt(prefix);
00151 }
00152 }
00153
00155 ~FlintSynonymTermList();
00156
00162 string get_termname() const;
00163
00165 Xapian::doccount get_termfreq() const;
00166
00168 Xapian::termcount get_collection_freq() const;
00169
00171 TermList * next();
00172
00174 TermList * skip_to(const string &tname);
00175
00177 bool at_end() const;
00178 };
00179
00180 #endif // XAPIAN_INCLUDED_FLINT_SYNONYM_H