Matt Chaput avatar 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().

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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.