00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_BRASS_SPELLING_H
00022 #define XAPIAN_INCLUDED_BRASS_SPELLING_H
00023
00024 #include <xapian/types.h>
00025
00026 #include "brass_lazytable.h"
00027 #include "termlist.h"
00028
00029 #include <map>
00030 #include <set>
00031 #include <string>
00032 #include <cstring>
00033
00034 namespace Brass {
00035
00036 struct fragment {
00037 char data[4];
00038
00039
00040 fragment() { }
00041
00042
00043 fragment(char data_[4]) { std::memcpy(data, data_, 4); }
00044
00045 char & operator[] (unsigned i) { return data[i]; }
00046 const char & operator[] (unsigned i) const { return data[i]; }
00047
00048 operator std::string () const {
00049 return std::string(data, data[0] == 'M' ? 4 : 3);
00050 }
00051
00052 bool operator<(const fragment &b) const {
00053 return std::memcmp(data, b.data, 4) < 0;
00054 }
00055 };
00056
00057 }
00058
00059 class BrassSpellingTable : public BrassLazyTable {
00060 void toggle_word(const std::string & word);
00061 void toggle_fragment(Brass::fragment frag, const std::string & word);
00062
00063 std::map<std::string, Xapian::termcount> wordfreq_changes;
00064
00073 std::map<Brass::fragment, std::set<std::string> > termlist_deltas;
00074
00075 public:
00084 BrassSpellingTable(const std::string & dbdir, bool readonly)
00085 : BrassLazyTable("spelling", dbdir + "/spelling.", readonly,
00086 Z_DEFAULT_STRATEGY) { }
00087
00088
00089 void merge_changes();
00090
00091 void add_word(const std::string & word, Xapian::termcount freqinc);
00092 void remove_word(const std::string & word, Xapian::termcount freqdec);
00093
00094 TermList * open_termlist(const std::string & word);
00095
00096 Xapian::doccount get_word_frequency(const std::string & word) const;
00097
00105 bool is_modified() const {
00106 return !wordfreq_changes.empty() || BrassTable::is_modified();
00107 }
00108
00109 void flush_db() {
00110 merge_changes();
00111 BrassTable::flush_db();
00112 }
00113
00114 void cancel() {
00115
00116 wordfreq_changes.clear();
00117 termlist_deltas.clear();
00118
00119 BrassTable::cancel();
00120 }
00121
00122
00123 };
00124
00126 class BrassSpellingTermList : public TermList {
00128 std::string data;
00129
00131 unsigned p;
00132
00134 std::string current_term;
00135
00137 BrassSpellingTermList(const BrassSpellingTermList &);
00138
00140 void operator=(const BrassSpellingTermList &);
00141
00142 public:
00144 BrassSpellingTermList(const std::string & data_)
00145 : data(data_), p(0) { }
00146
00147 Xapian::termcount get_approx_size() const;
00148
00149 std::string get_termname() const;
00150
00151 Xapian::termcount get_wdf() const;
00152
00153 Xapian::doccount get_termfreq() const;
00154
00155 Xapian::termcount get_collection_freq() const;
00156
00157 TermList * next();
00158
00159 TermList * skip_to(const std::string & term);
00160
00161 bool at_end() const;
00162
00163 Xapian::termcount positionlist_count() const;
00164
00165 Xapian::PositionIterator positionlist_begin() const;
00166 };
00167
00168 #endif // XAPIAN_INCLUDED_BRASS_SPELLING_H