1. Matt Chaput
  2. whoosh

Commits

Matt Chaput  committed 350feef

Fixed filter code to call .docs() on Results object, because .docset is lazy.
Thanks very, very much to Andy Kittner for the patch.
Fixes issue #376.

  • Participants
  • Parent commits 2251770
  • Branches default

Comments (0)

Files changed (2)

File src/whoosh/searching.py

View file
  • Ignore whitespace
         if isinstance(obj, (set, DocIdSet)):
             c = obj
         elif isinstance(obj, Results):
-            c = obj.docset
+            c = obj.docs()
         elif isinstance(obj, ResultsPage):
-            c = obj.results.docset
+            c = obj.results.docs()
         elif isinstance(obj, query.Query):
             c = self._query_to_comb(obj)
         else:

File tests/test_results.py

View file
  • Ignore whitespace
 from whoosh.codec.whoosh3 import W3Codec
 from whoosh.compat import u, xrange, text_type, permutations
 from whoosh.filedb.filestore import RamStorage
-from whoosh.util.testing import TempStorage
+from whoosh.util.testing import TempStorage, TempIndex
 
 
 def test_score_retrieval():
         hit = r[0]
         assert hit["content"] == "bravo"
         assert hit.highlights("content") == ""
+
+
+def test_filter_by_result():
+    schema = fields.Schema(title=fields.TEXT(stored=True),
+                           content=fields.TEXT(stored=True))
+
+    with TempIndex(schema, "filter") as ix:
+        words = u("foo bar baz qux barney").split()
+        with ix.writer() as w:
+            for x in xrange(100):
+                t = "even" if x % 2 == 0 else "odd"
+                c = words[x % len(words)]
+                w.add_document(title=t, content=c)
+
+        with ix.searcher() as searcher:
+            fq = query.Term("title", "even")
+            filter_result = searcher.search(fq)
+            assert filter_result.docset is None
+
+            q = query.Term("content", "foo")
+
+            # filter_result.docs()
+            result = searcher.search(q, filter=filter_result)
+            assert all(x["title"] == "even" and x["content"] == "foo"
+                       for x in result)
+