Commits

Matt Chaput committed a5a5b1e

FilterCollector was asking for self.child.offset but it should just keep track of the offset itself.
Fixes issue #274.

  • Participants
  • Parent commits a1e09af

Comments (0)

Files changed (2)

File src/whoosh/collectors.py

         self._restrict = ftc(restrict) if restrict else None
         self.filtered_count = 0
 
+    def set_subsearcher(self, subsearcher, offset):
+        self.offset = offset
+        self.child.set_subsearcher(subsearcher, offset)
+
     def collect_matches(self):
         child = self.child
         _allow = self._allow
         _restrict = self._restrict
-        filtered_count = self.filtered_count
 
-        for sub_docnum in child.matches():
-            global_docnum = child.offset + sub_docnum
-            if ((_allow and global_docnum not in _allow)
-                or (_restrict and global_docnum in _restrict)):
-                filtered_count += 1
-                continue
-
-            child.collect(sub_docnum)
-
-        self.filtered_count = filtered_count
+        if _allow or _restrict:
+            filtered_count = self.filtered_count
+            for sub_docnum in child.matches():
+                global_docnum = self.offset + sub_docnum
+                if ((_allow and global_docnum not in _allow)
+                    or (_restrict and global_docnum in _restrict)):
+                    filtered_count += 1
+                    continue
+                child.collect(sub_docnum)
+            self.filtered_count = filtered_count
+        else:
+            # If there was no allow or restrict set, don't do anything special,
+            # just forward the call to the child collector
+            child.collect_matches()
 
     def results(self):
         r = self.child.results()

File tests/test_sorting.py

 from nose.tools import assert_equal  # @UnresolvedImport
 
 from whoosh import fields, query, sorting
-from whoosh.compat import b, u, xrange, long_type
+from whoosh.compat import b, u
+from whoosh.compat import permutations, xrange
 from whoosh.filedb.filestore import RamStorage
 from whoosh.util.testing import skip_if_unavailable, skip_if, TempIndex
 
     test(ix)
 
 
+def test_filtered_grouped():
+    schema = fields.Schema(tag=fields.ID, text=fields.TEXT(stored=True))
+    ix = RamStorage().create_index(schema)
+    domain = u("alfa bravo charlie delta echo foxtrot").split()
 
+    with ix.writer() as w:
+        for i, ls in enumerate(permutations(domain, 3)):
+            tag = u(str(i % 3))
+            w.add_document(tag=tag, text=u(" ").join(ls))
 
+    with ix.searcher() as s:
+        f = query.And([query.Term("text", "charlie"),
+                       query.Term("text", "delta")])
+        r = s.search(query.Every(), filter=f, groupedby="tag", limit=None)
+        assert_equal(len(r), 24)
 
 
 
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+