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 "omdebug.h"
00030 #include "termlist.h"
00031
00032 #include <set>
00033 #include <string>
00034
00035 class FlintSynonymTable : public FlintTable {
00037 mutable std::string last_term;
00038
00040 mutable std::set<std::string> last_synonyms;
00041
00042 public:
00051 FlintSynonymTable(std::string dbdir, bool readonly)
00052 : FlintTable(dbdir + "/synonym.", readonly, Z_DEFAULT_STRATEGY, true) { }
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() || FlintTable::is_modified();
00096 }
00097
00098 void create_and_open(unsigned int blocksize) {
00099
00100
00101 FlintTable::erase();
00102 FlintTable::set_block_size(blocksize);
00103 }
00104
00105 void commit(flint_revision_number_t revision) {
00106 merge_changes();
00107 FlintTable::commit(revision);
00108 }
00109
00110 void cancel() {
00111 discard_changes();
00112 FlintTable::cancel();
00113 }
00114
00115
00116 };
00117
00118 class FlintCursor;
00119
00120 class FlintSynonymTermList : public AllTermsList {
00122 FlintSynonymTermList(const FlintSynonymTermList &);
00123
00125 void operator=(const FlintSynonymTermList &);
00126
00128 Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database;
00129
00133 FlintCursor * cursor;
00134
00136 Xapian::termcount size;
00137
00139 string prefix;
00140
00141 public:
00142 FlintSynonymTermList(Xapian::Internal::RefCntPtr<const Xapian::Database::Internal> database_,
00143 FlintCursor * cursor_,
00144 Xapian::termcount size_,
00145 const string & prefix_)
00146 : database(database_), cursor(cursor_), size(size_), prefix(prefix_)
00147 {
00148
00149
00150 if (prefix.empty()) {
00151 cursor->find_entry(string());
00152 } else {
00153
00154 cursor->find_entry_lt(prefix);
00155 }
00156 }
00157
00159 ~FlintSynonymTermList();
00160
00166 string get_termname() const;
00167
00169 Xapian::doccount get_termfreq() const;
00170
00172 Xapian::termcount get_collection_freq() const;
00173
00175 TermList * next();
00176
00178 TermList * skip_to(const string &tname);
00179
00181 bool at_end() const;
00182 };
00183
00184 #endif // XAPIAN_INCLUDED_FLINT_SYNONYM_H