1. Matt Chaput
  2. whoosh
  3. Issues
Issue #324 resolved

Highlighting under Python 3 fails

Anonymous 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. 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?

  2. Log in to comment