]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Fix RegexpPostingSource
authorOlly Betts <olly@survex.com>
Tue, 7 Mar 2017 12:52:39 +0000 (08:52 -0400)
committerDavid Bremner <david@tethera.net>
Tue, 7 Mar 2017 23:44:36 +0000 (19:44 -0400)
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).

lib/regexp-fields.cc
lib/regexp-fields.h

index b41747502e1e6b8bbea31044e583e10b75a155a3..8e740a810064a8e80bae40ad75045b975c7c2286 100644 (file)
@@ -62,11 +62,6 @@ RegexpPostingSource::init (const Xapian::Database &db)
     it_ = db_.valuestream_begin (slot_);
     end_ = db.valuestream_end (slot_);
     started_ = false;
     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
 }
 
 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")
 static inline Xapian::valueno _find_slot (std::string prefix)
 {
     if (prefix == "from")
index bac119998c56ca759b46a58c27881ad9dad374a0..a4ba7ad8412cebbf8a2104f4058548abc277a8fc 100644 (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));
     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));
 };
 
 
 };