Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Solr: use nested query syntax for AltParser queries #723

Merged
merged 1 commit into from Jan 30, 2013
Commits on Jan 28, 2013
  1. Solr: use nested query syntax for AltParser queries

    acdha committed Jan 23, 2013
    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
    
    * Tests updated for the new query generation output
    * A Solr backend task was added to actually run the dismax queries and verify
      that we're not getting Solr 400s errors due to syntax gremlins