Commits

Matt Chaput  committed c865b56

Fixed setting of matcher, offset, subsearcher attrs on wrapping collectors. Fixes issue #294.

  • Participants
  • Parent commits a6fbf6f

Comments (0)

Files changed (2)

File src/whoosh/collectors.py

 
     def set_subsearcher(self, subsearcher, offset):
         self.child.set_subsearcher(subsearcher, offset)
+        self.subsearcher = subsearcher
+        self.matcher = self.child.matcher
+        self.offset = self.child.offset
 
     def all_ids(self):
         return self.child.all_ids()
         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 all_ids(self):
         child = self.child
 
         self.child.prepare(top_searcher, q, context)
 
     def set_subsearcher(self, subsearcher, offset):
-        child = self.child
-        child.set_subsearcher(subsearcher, offset)
+        WrappingCollector.set_subsearcher(self, subsearcher, offset)
 
         # Tell each categorizer about the new subsearcher and offset
         for categorizer in itervalues(self.categorizers):
-            categorizer.set_searcher(child.subsearcher, child.offset)
+            categorizer.set_searcher(self.child.subsearcher, self.child.offset)
 
     def collect(self, sub_docnum):
         matcher = self.child.matcher
                            context.set(needs_current=needs_current))
 
     def set_subsearcher(self, subsearcher, offset):
-        self.child.set_subsearcher(subsearcher, offset)
+        WrappingCollector.set_subsearcher(self, subsearcher, offset)
+
+        # Tell the keyer and (optional) orderer about the new subsearcher
         self.keyer.set_searcher(subsearcher, offset)
         if self.orderer:
             self.orderer.set_searcher(subsearcher, offset)
         self.docterms = defaultdict(list)
 
     def set_subsearcher(self, subsearcher, offset):
-        child = self.child
-        child.set_subsearcher(subsearcher, offset)
+        WrappingCollector.set_subsearcher(self, subsearcher, offset)
+
         # Store a list of all the term matchers in the matcher tree
-        self.termmatchers = list(child.matcher.term_matchers())
+        self.termmatchers = list(self.child.matcher.term_matchers())
 
     def collect(self, sub_docnum):
         child = self.child

File tests/test_searching.py

     with ix.searcher() as s:
         r = s.search_page(query.Term("tags", "keyword3"), 1)
         assert r
+
+
+def test_groupedby_with_terms():
+    schema = fields.Schema(content=fields.TEXT, organism=fields.ID)
+    ix = RamStorage().create_index(schema)
+
+    with ix.writer() as w:
+        w.add_document(organism=u("mus"), content=u("IPFSTD1 IPFSTD_kdwq134 Kaminski-all Study00:00:00"))
+        w.add_document(organism=u("mus"), content=u("IPFSTD1 IPFSTD_kdwq134 Kaminski-all Study"))
+        w.add_document(organism=u("hs"), content=u("This is the first document we've added!"))
+
+    with ix.searcher() as s:
+        q = qparser.QueryParser("content", schema=ix.schema).parse(u("IPFSTD1"))
+        r = s.search(q, groupedby=["organism"], terms=True)
+        assert len(r) == 2
+        assert r.groups("organism") == {"mus": [1, 0]}
+        assert r.has_matched_terms()
+        assert r.matched_terms() == set([('content', 'ipfstd1')])
+
+
+
+
+
+
+
+
+