Highlighting under Python 3 fails

Create issue
Issue #324 resolved
Former user created an issue

This same code works fine under Python 2, but when run under Python 3, it blows up with the following traceback:

>>> from whoosh import analysis
>>> from whoosh.highlight import highlight, ContextFragmenter, UppercaseFormatter
>>> sa = analysis.StemmingAnalyzer()
>>> highlight('Indexed!\n1', ['index'], sa, ContextFragmenter(terms), UppercaseFormatter())

Traceback (most recent call last):
  File "/Users/daniel/Code/Python/django-haystack/tests/whoosh_tests/tests/whoosh_backend.py", line 224, in test_search
    self.assertEqual(self.sb.search(u'index*', highlight=True)['hits'], 23)
  File "/Users/daniel/Code/Python/django-haystack/haystack/backends/__init__.py", line 33, in wrapper
    return func(obj, query_string, *args, **kwargs)
  File "/Users/daniel/Code/Python/django-haystack/haystack/backends/whoosh_backend.py", line 425, in search
    results = self._process_results(raw_page, highlight=highlight, query_string=query_string, spelling_query=spelling_query, result_class=result_class)
  File "/Users/daniel/Code/Python/django-haystack/haystack/backends/whoosh_backend.py", line 610, in _process_results
    self.content_field_name: [highlight(additional_fields.get(self.content_field_name), terms, sa, ContextFragmenter(terms), UppercaseFormatter())],
  File "/Users/daniel/Code/Python/django-haystack/env3/lib/python3.3/site-packages/whoosh/highlight.py", line 785, in highlight
    fragments = top_fragments(fragments, top, scorer, order)
  File "/Users/daniel/Code/Python/django-haystack/env3/lib/python3.3/site-packages/whoosh/highlight.py", line 759, in top_fragments
    scored_fragments = nlargest(count, scored_fragments)
  File "/Users/daniel/Code/Python/django-haystack/env3/bin/../lib/python3.3/heapq.py", line 451, in nlargest
    result = _nlargest(n, it)
  File "/Users/daniel/Code/Python/django-haystack/env3/lib/python3.3/site-packages/whoosh/highlight.py", line 758, in <genexpr>
    scored_fragments = ((scorer(f), f) for f in fragments)
  File "/Users/daniel/Code/Python/django-haystack/env3/lib/python3.3/site-packages/whoosh/highlight.py", line 351, in fragment_tokens
    elif currentlen + tlength > maxchars:
TypeError: unorderable types: int() > list()

Happens under Whoosh 2.4.1, Python 3.3.2, OS X 10.8.4.

Comments (5)

  1. Daniel Lindsley

    I'd be happy to provide more details (as well as will log into BitBucket before posting issues next time 😖).

  2. Matt Chaput repo owner

    It looks like this is fixed in the current repo. I'm going to make a release this weekend.

  3. Matt Chaput repo owner

    Going to mark this resolved, please check with the latest repo or version 2.5 from PyPI and re-open if you still see this. Thanks!

  4. Daniel Lindsley

    I tried this on Whoosh 2.5.1 & it's still an issue. Passes under Python 2.7, fails under Python 3.3.2.

  5. Matt Chaput repo owner

    I have the code above in a test case (tests/test_highlighting.py/test_issue324()) and it passes for me under Python 3.3. Can you look at that and see if you're doing something different?

  6. Log in to comment