Commits

Matt Chaput committed 60e03ba

Fixed bug where InverseMatcher would match deleted documents. See issue #266.
InverseMatcher only checked missing() when advancing the underlying matcher.
If the underlying matcher was exhausted and IM was just increasing self._id, it
wasn't checking missing().

  • Participants
  • Parent commits f77aa15

Comments (0)

Files changed (2)

src/whoosh/matching/wrappers.py

         if not child.is_active() and not missing(self._id):
             return
 
+        # Skip missing documents
+        while self._id < self.limit and missing(self._id):
+            self._id += 1
+
         # Catch the child matcher up to where this matcher is
         if child.is_active() and child.id() < self._id:
             child.skip_to(self._id)

tests/test_fields.py

         # Try doing a search for documents where b=True
         qp = qparser.QueryParser("b", ix.schema)
         q = qp.parse("b:t")
-        r = s.search(q)
+        r = s.search(q, limit=None)
         assert_equal(len(r), 0)
 
+        # Make sure Every query doesn't match deleted docs
+        r = s.search(qp.parse("*"), limit=None)
+        assert not any(hit["b"] for hit in r)
+        assert not any(reader.is_deleted(hit.docnum) for hit in r)
+
+        r = s.search(qp.parse("*:*"), limit=None)
+        assert not any(hit["b"] for hit in r)
+        assert not any(reader.is_deleted(hit.docnum) for hit in r)
+
+        # Make sure Not query doesn't match deleted docs
+        q = qp.parse("NOT b:t")
+        r = s.search(q, limit=None)
+        assert not any(hit["b"] for hit in r)
+        assert not any(reader.is_deleted(hit.docnum) for hit in r)
+
+        r = s.search(q, limit=5)
+        assert not any(hit["b"] for hit in r)
+        assert not any(reader.is_deleted(hit.docnum) for hit in r)
+
 
 def test_missing_field():
     schema = fields.Schema()