lib: Fix RegexpPostingSource

Remove incorrect skipping to first match from init(), and add explicit
skip_to() and check() methods to work around xapian-core bug (the
check() method will also improve speed when filtering by one of
these).
This commit is contained in:
Olly Betts 2017-03-07 08:52:39 -04:00 committed by David Bremner
parent 9208289eea
commit 81bd72cebb
2 changed files with 23 additions and 5 deletions

View file

@ -62,11 +62,6 @@ RegexpPostingSource::init (const Xapian::Database &db)
it_ = db_.valuestream_begin (slot_);
end_ = db.valuestream_end (slot_);
started_ = false;
/* make sure we start on a matching value */
while (!at_end() && regexec (&regexp_, (*it_).c_str (), 0, NULL, 0) != 0) {
++it_;
}
}
Xapian::doccount
@ -113,6 +108,27 @@ RegexpPostingSource::next (unused (double min_wt))
}
}
void
RegexpPostingSource::skip_to (Xapian::docid did, unused (double min_wt))
{
started_ = true;
it_.skip_to (did);
for (; ! at_end (); ++it_) {
std::string value = *it_;
if (regexec (&regexp_, value.c_str (), 0, NULL, 0) == 0)
break;
}
}
bool
RegexpPostingSource::check (Xapian::docid did, unused (double min_wt))
{
started_ = true;
if (!it_.check (did) || at_end ())
return false;
return (regexec (&regexp_, (*it_).c_str (), 0, NULL, 0) == 0);
}
static inline Xapian::valueno _find_slot (std::string prefix)
{
if (prefix == "from")

View file

@ -56,6 +56,8 @@ class RegexpPostingSource : public Xapian::PostingSource
Xapian::docid get_docid () const;
bool at_end () const;
void next (unused (double min_wt));
void skip_to (Xapian::docid did, unused (double min_wt));
bool check (Xapian::docid did, unused (double min_wt));
};