32 #include "../prefix_compressed_strings.h"
46 for (
auto i : termlist_deltas) {
47 const string& key = i.first;
48 const set<string>& changes = i.second;
50 auto d = changes.begin();
51 if (d == changes.end())
continue;
56 if (get_exact_entry(key, current)) {
58 updated.reserve(current.size());
59 while (!in.
at_end() && d != changes.end()) {
60 const string & word = *in;
61 Assert(d != changes.end());
62 int cmp = word.compare(*d);
83 while (d != changes.end()) {
86 if (!updated.empty()) {
92 termlist_deltas.clear();
94 map<string, Xapian::termcount>::const_iterator j;
95 for (j = wordfreq_changes.begin(); j != wordfreq_changes.end(); ++j) {
96 string key =
"W" + j->first;
105 wordfreq_changes.clear();
111 auto i = termlist_deltas.find(frag);
112 if (i == termlist_deltas.end()) {
113 i = termlist_deltas.insert(make_pair(frag, set<string>())).first;
117 auto res = i->second.insert(word);
120 i->second.erase(res.first);
127 if (word.size() <= 1)
return;
129 map<string, Xapian::termcount>::iterator i = wordfreq_changes.find(word);
130 if (i != wordfreq_changes.end()) {
133 i->second += freqinc;
140 string key =
"W" + word;
142 if (get_exact_entry(key, data)) {
145 const char * p = data.data();
149 wordfreq_changes[word] = freq + freqinc;
152 wordfreq_changes[word] = freqinc;
162 if (word.size() <= 1)
return;
164 map<string, Xapian::termcount>::iterator i = wordfreq_changes.find(word);
165 if (i != wordfreq_changes.end()) {
166 if (i->second == 0) {
171 if (freqdec < i->second) {
172 i->second -= freqdec;
179 string key =
"W" + word;
181 if (!get_exact_entry(key, data)) {
187 const char *p = data.data();
191 if (freqdec < freq) {
192 wordfreq_changes[word] = freq - freqdec;
196 wordfreq_changes[word] = 0;
212 toggle_fragment(buf, word);
216 buf[1] = word[word.size() - 2];
217 buf[2] = word[word.size() - 1];
219 toggle_fragment(buf, word);
221 if (word.size() <= 4) {
231 toggle_fragment(buf, word);
233 if (word.size() > 2) {
237 for (
size_t start = 0; start <= word.size() - 3; ++start) {
238 memcpy(buf.
data + 1, word.data() + start, 3);
241 if (done.insert(buf).second)
242 toggle_fragment(buf, word);
261 if (!wordfreq_changes.empty()) merge_changes();
274 if (get_exact_entry(
string(buf), data))
279 buf[1] = word[word.size() - 2];
280 buf[2] = word[word.size() - 1];
281 if (get_exact_entry(
string(buf), data))
284 if (word.size() <= 4) {
293 if (get_exact_entry(
string(buf), data))
296 if (word.size() > 2) {
299 for (
size_t start = 0; start <= word.size() - 3; ++start) {
300 memcpy(buf.
data + 1, word.data() + start, 3);
301 if (get_exact_entry(
string(buf), data))
305 if (word.size() == 3) {
312 if (get_exact_entry(
string(buf), data))
318 if (get_exact_entry(
string(buf), data))
330 if (get_exact_entry(
string(buf), data))
333 if (get_exact_entry(
string(buf), data))
337 if (pq.empty())
return NULL;
346 while (pq.size() > 1) {
352 termlist =
new OrTermList(pq.top(), termlist);
361 while (!pq.empty()) {
372 map<string, Xapian::termcount>::const_iterator i;
373 i = wordfreq_changes.find(word);
374 if (i != wordfreq_changes.end()) {
379 string key =
"W" + word;
381 if (get_exact_entry(key, data)) {
384 const char *p = data.data();
425 if (p == data.size()) {
430 if (!current_term.empty()) {
431 if (p == data.size())
436 if (p == data.size() ||
439 current_term.append(data.data() + p + 1, add);
447 while (!data.empty() && current_term < term) {
Spelling correction data for a chert database.
void toggle_word(const std::string &word)
TermList * open_termlist(const std::string &word)
Xapian::doccount get_word_frequency(const std::string &word) const
void toggle_fragment(fragment frag, const std::string &word)
void remove_word(const std::string &word, Xapian::termcount freqdec)
void add_word(const std::string &word, Xapian::termcount freqinc)
The list of words containing a particular trigram.
Xapian::termcount get_wdf() const
Return the wdf for the term at the current position.
TermList * next()
Advance the current position to the next term in the termlist.
Xapian::PositionIterator positionlist_begin() const
Return a PositionIterator for the current position.
std::string get_termname() const
Return the termname at the current position.
TermList * skip_to(const std::string &term)
Skip forward to the specified term.
Xapian::termcount positionlist_count() const
Return the length of the position list for the current position.
Xapian::doccount get_termfreq() const
Return the term frequency for the term at the current position.
bool at_end() const
Return true if the current position is past the last term in this list.
Xapian::termcount get_approx_size() const
Return approximate size of this termlist.
void append(const std::string &word)
DatabaseCorruptError indicates database corruption was detected.
Class for iterating over term positions.
Abstract base class for termlists.
virtual Xapian::termcount get_approx_size() const =0
Return approximate size of this termlist.
UnimplementedError indicates an attempt to use an unimplemented feature.
Hierarchy of classes which Xapian can throw as exceptions.
Collate statistics and calculate the term weights for the ESet.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
Various assertion macros.
#define AssertRel(A, REL, B)
Merge two TermList objects using an OR operation.
Pack types into strings and unpack them again.
bool unpack_uint_last(const char **p, const char *end, U *result)
Decode an unsigned integer as the last item in a string.
void pack_uint_last(std::string &s, U value)
Append an encoded unsigned integer to a string as the last item.
bool operator()(const TermList *a, const TermList *b) const