Issue #396 new

Quotes searches crash Whoosh 2.6.0 on Django

Robert Rollins
created an issue

I'm using Whoosh 2.6.0 in Django with Django-haystack 2.2.0, and every time I try to search for a quoted string, I get an exception:

Django Version: 1.6.5
Python Version: 2.6.9
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'south',
 'template',
 'suit',
 'suit_ckeditor',
 'adminsortable',
 'personnel',
 'haystack',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'menu',
 'attachments',
 'static_pages')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/path_to_code/python2.6/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/path_to_app/personnel/views.py" in search
  22.     return _return_correct_results_template(request, personnel_results, departmental_results, on_campus, searchtext)
File "/path_to_app/personnel/views.py" in _return_correct_results_template
  88.     if not personnel_results and not departmental_results:
File "/path_to_code/python2.6/site-packages/haystack/query.py" in __len__
  91.             self._result_count = self.query.get_count()
File "/path_to_code/python2.6/site-packages/haystack/backends/__init__.py" in get_count
  625.                 self.run()
File "/path_to_code/python2.6/site-packages/haystack/backends/__init__.py" in run
  562.         results = self.backend.search(final_query, **search_kwargs)
File "/path_to_code/python2.6/site-packages/haystack/backends/__init__.py" in wrapper
  34.             return func(obj, query_string, *args, **kwargs)
File "/path_to_code/python2.6/site-packages/haystack/backends/whoosh_backend.py" in search
  424.                     **search_kwargs
File "/path_to_code/python2.6/site-packages/whoosh/searching.py" in search_page
  640.         results = self.search(query, limit=pagenum * pagelen, **kwargs)
File "/path_to_code/python2.6/site-packages/whoosh/searching.py" in search
  787.         self.search_with_collector(q, c)
File "/path_to_code/python2.6/site-packages/whoosh/searching.py" in search_with_collector
  820.         collector.run()
File "/path_to_code/python2.6/site-packages/whoosh/collectors.py" in run
  143.                 self.set_subsearcher(subsearcher, offset)
File "/path_to_code/python2.6/site-packages/whoosh/collectors.py" in set_subsearcher
  618.         self.child.set_subsearcher(subsearcher, offset)
File "/path_to_code/python2.6/site-packages/whoosh/collectors.py" in set_subsearcher
  171.         self.matcher = self.q.matcher(subsearcher, self.context)
File "/path_to_code/python2.6/site-packages/whoosh/query/positional.py" in matcher
  222.                                    % self.fieldname)

Exception Type: QueryError at /personnel/search
Exception Value: Phrase search: 'text' field has no positions

Commenting out the code at line 222 makes the error go away, as long as the search returns no results. If the quoted search would return a result, however, this exception is thrown:

Traceback:
File "/path_to_code/python2.6/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/path_to_app/personnel/views.py" in search
  22.     return _return_correct_results_template(request, personnel_results, departmental_results, on_campus, searchtext)
File "/path_to_app/personnel/views.py" in _return_correct_results_template
  88.     if not personnel_results and not departmental_results:
File "/path_to_code/python2.6/site-packages/haystack/query.py" in __len__
  91.             self._result_count = self.query.get_count()
File "/path_to_code/python2.6/site-packages/haystack/backends/__init__.py" in get_count
  625.                 self.run()
File "/path_to_code/python2.6/site-packages/haystack/backends/__init__.py" in run
  562.         results = self.backend.search(final_query, **search_kwargs)
File "/path_to_code/python2.6/site-packages/haystack/backends/__init__.py" in wrapper
  34.             return func(obj, query_string, *args, **kwargs)
File "/path_to_code/python2.6/site-packages/haystack/backends/whoosh_backend.py" in search
  424.                     **search_kwargs
File "/path_to_code/python2.6/site-packages/whoosh/searching.py" in search_page
  640.         results = self.search(query, limit=pagenum * pagelen, **kwargs)
File "/path_to_code/python2.6/site-packages/whoosh/searching.py" in search
  787.         self.search_with_collector(q, c)
File "/path_to_code/python2.6/site-packages/whoosh/searching.py" in search_with_collector
  820.         collector.run()
File "/path_to_code/python2.6/site-packages/whoosh/collectors.py" in run
  143.                 self.set_subsearcher(subsearcher, offset)
File "/path_to_code/python2.6/site-packages/whoosh/collectors.py" in set_subsearcher
  618.         self.child.set_subsearcher(subsearcher, offset)
File "/path_to_code/python2.6/site-packages/whoosh/collectors.py" in set_subsearcher
  171.         self.matcher = self.q.matcher(subsearcher, self.context)
File "/path_to_code/python2.6/site-packages/whoosh/query/positional.py" in matcher
  241.         m = q.matcher(searcher, context)
File "/path_to_code/python2.6/site-packages/whoosh/query/spans.py" in matcher
  561.                                      mindist=self.mindist)
File "/path_to_code/python2.6/site-packages/whoosh/query/spans.py" in __init__
  570.             super(SpanNear2.SpanNear2Matcher, self).__init__(isect)
File "/path_to_code/python2.6/site-packages/whoosh/query/spans.py" in __init__
  196.             self._find_next()
File "/path_to_code/python2.6/site-packages/whoosh/query/spans.py" in _find_next
  213.         spans = self._get_spans()
File "/path_to_code/python2.6/site-packages/whoosh/query/spans.py" in _get_spans
  588.             aspans = ms[0].spans()
File "/path_to_code/python2.6/site-packages/whoosh/matching/mcore.py" in spans
  610.                             % self.term())

Exception Type: TypeError at /personnel/search
Exception Value: not all arguments converted during string formatting

It's hard to tell which codebase is at fault here. It could be Whoosh's fault, or Django-haystack may be using Whoosh improperly. I'm going to post this to both projects' groups, to hopefully find a solution quickly.

Comments (4)

  1. Log in to comment