Issue #294 resolved causes error when groupedby and terms=True

created an issue

When a is used with groupedby and terms= True causes an error (see in the code segment)

The actual query does not matter, the facet can be one or many, simple fieldname or FieldFacet(maptype= Count). This was not present in 2.3.2.

In the code segment command1, command2 generate the same error, whereas command3 generates a slightly different one. Is it that TermCollector and FacetCollector cannot be combined, i.e the groupedby and terms cannot both be specified?

from whoosh.index import create_in
from whoosh.fields import *
from whoosh import sorting 
from whoosh.qparser import QueryParser
from whoosh import collectors

# create an index
schema = Schema(content=TEXT(), organism=ID())
ix = create_in("./data", schema, "test_whoosh_db")
writer = ix.writer()
writer.add_document(organism=u"mus", content=u"IPFSTD1 IPFSTD_kdwq134 Kaminski-all Study00:00:00")
writer.add_document(organism=u"mus", content=u"IPFSTD1 IPFSTD_kdwq134 Kaminski-all Study")
writer.add_document(organism=u"hs", content=u"This is the first document we've added!")

facets = ['organism'] #also with {'organism':sorting.FieldFacet('organism', maptype=sorting.Count)}

qp = QueryParser("content", schema=ix.schema)
q = qp.parse(u"IPFSTD1")

with ix.searcher() as s:
    # command1
    results =, groupedby= facets, terms= True)
    print len(results) 
    # command2
    c = s.collector(groupedby= facets, terms= True) 
    s.search_with_collector(q, c)
    print len(c.results())    

##  File "..... /lib/python2.7/site-packages/Whoosh-2.4.1-py2.7.egg/whoosh/", line 942, in set_subsearcher
##    self.termmatchers = list(child.matcher.term_matchers())
##AttributeError: 'FacetCollector' object has no attribute 'matcher'
    # command3  
    uc = collectors.UnlimitedCollector()
    tc = collectors.TermsCollector(uc)   
    fc = collectors.FacetCollector(tc, groupedby= facets, maptype= sorting.Count)
    s.search_with_collector(q, fc)
    print len(fc.results())
##  File "... /lib/python2.7/site-packages/Whoosh-2.4.1-py2.7.egg/whoosh/", line 675, in set_subsearcher
##    categorizer.set_searcher(child.subsearcher, child.offset)
##AttributeError: 'TermsCollector' object has no attribute 'subsearcher'    

Comments (5)

  1. Log in to comment