toastdriven/django-haystack — pull request #723 by acdha (2013-01-23 00:35:04+00:00)
Title: Solr: use nested query syntax for AltParser queries

The previous implementation would, given a query like this::

sqs.filter(content=AltParser('dismax', 'library', qf="title^2 text" mm=1))

generate a query like this::

{!dismax v=library qf="title^2 text" mm=1}

This works in certain situations but causes Solr to choke while parsing it
when Haystack wraps this term in parentheses::

org.apache.lucene.queryParser.ParseException: Cannot parse '({!dismax mm=1 qf='title^2 text institution^0.8' v=library})':
Encountered " <RANGEEX_GOOP> "qf=\'title^1.25 "" at line 1, column 16.

The solution is to use the nested query syntax described here:

http://searchhub.org/2009/03/31/nested-queries-in-solr/

This will produce a query like this, which works with Solr 3.6.2::

(_query_:"{!edismax mm=1 qf='title^1.5 text institution^0.5' v=library}")

Leaving the actual URL query string looking like this::

q=%28_query_%3A%22%7B%21edismax+mm%3D1+qf%3D%27title%5E1.5+text+institution%5E0.5%27+v%3Dlibrary%7D%22%29