Issue #356 resolved

KeyError when trying to collapse results

Michael Elsdörfer
created an issue

Using 2.5.2

This is the schema:

schema = Schema(
        # sortable because we collapse on it
        version=ID(unique=True, stored=True, sortable=True),
        page=ID(stored=True, sortable=True),
        title=TEXT(stored=True, field_boost=2, spelling=True),
        content=TEXT(stored=True, spelling=True),
        published=BOOLEAN(stored=True),
        modified=DATETIME(stored=True))

This is how I search:

index = open_index(self.app, readonly=False)
        searcher = index.searcher()
        qparser = MultifieldParser(['title', 'content'], index.schema)
        results = searcher.search(
            query.And([qparser.parse(unicode(q)) for q in ns.query]),
            collapse=FieldFacet('page'),
            collapse_order=[
                FieldFacet('published', reverse=True),
                FieldFacet('version', reverse=True)
            ])

This is the exception I see:

...
  File "/Users/michael/.virtualenvs/cms/lib/python2.7/site-packages/whoosh/searching.py", line 787, in search
    self.search_with_collector(q, c)
  File "/Users/michael/.virtualenvs/cms/lib/python2.7/site-packages/whoosh/searching.py", line 820, in search_with_collector
    collector.run()
  File "/Users/michael/.virtualenvs/cms/lib/python2.7/site-packages/whoosh/collectors.py", line 143, in run
    self.collect_matches()
  File "/Users/michael/.virtualenvs/cms/lib/python2.7/site-packages/whoosh/collectors.py", line 979, in collect_matches
    child.remove(best.pop()[1])
  File "/Users/michael/.virtualenvs/cms/lib/python2.7/site-packages/whoosh/collectors.py", line 497, in remove
    raise KeyError(global_docnum)
KeyError: 2084L

Note that this error occurs for most search terms - but not all. Some work fine, and they do so even if collapsing is going on.

Comments (6)

  1. Matt Chaput repo owner

    I can't seem to reproduce this. Can you reduce it to a test case, or share the index and the code necessary to reproduce the error? Thanks!

  2. Log in to comment