whoosh-community / whoosh

Whoosh is a fast, featureful full-text indexing and searching library implemented in pure Python.
Other
246 stars 37 forks source link

Search with filter raises exception: AttributeError: 'TermsCollector' object has no attribute 'offset' #302

Closed fortable1999 closed 11 years ago

fortable1999 commented 11 years ago

Original report by Rishi Sharma (Bitbucket: rishimedia, GitHub: Unknown).


Hi Matt: First I must say you have put together a beautiful product. One issue that I am having is regarding the filter on search. When the filter arg is passed a value (in my case a python set), I get the following error:

Traceback (most recent call last):

#!python

  File "./views.py", line 65, in query_index
    results = s.search_page(q, pagenum=pg, pagelen=10, terms=True, filter=working_set)
  File "/home/rishi/Projects/ngeluta/local/lib/python2.7/site-packages/whoosh/searching.py", line 561, in search_page
    results = self.search(query, limit=pagenum * pagelen, **kwargs)
  File "/home/rishi/Projects/ngeluta/local/lib/python2.7/site-packages/whoosh/searching.py", line 762, in search
    self.search_with_collector(q, c)
  File "/home/rishi/Projects/ngeluta/local/lib/python2.7/site-packages/whoosh/searching.py", line 804, in search_with_collector
    collector.collect_matches()
  File "/home/rishi/Projects/ngeluta/local/lib/python2.7/site-packages/whoosh/collectors.py", line 598, in collect_matches
    global_docnum = child.offset + sub_docnum
AttributeError: 'TermsCollector' object has no attribute 'offset'

Here is the context of my issue:

#!python

def query_index(phrase, pg=1, working_set=set([1,2,3])):
    ix = open_dir("indexdir", indexname="jobs")
    qp = QueryParser('position_text', schema=ix.schema)
    q = qp.parse(unicode(phrase))

    with ix.searcher() as s:
        s.set_caching_policy(save=False)
        results = s.search_page(q, pagenum=pg, pagelen=10, terms=True, filter=working_set)
fortable1999 commented 11 years ago

Original comment by Matt Chaput (Bitbucket: mchaput, GitHub: mchaput).


Sorry for taking so long to get to this. This seems to be fixed in the repo version. Will make a new release soon.

fortable1999 commented 11 years ago

Original comment by Matt Chaput (Bitbucket: mchaput, GitHub: mchaput).


Added test for filtering and saving terms at the same time. See issue #302.