sunspot/sunspot — pull request #118 by Marchino (2011-11-05 15:24:05+00:00)
Title: fixed syntax of highlighted fields on dismax queries

I found a problem with nested dismax queries and syntax highlighting.

Whenever a dismax query with syntax highlighting is performed I got a parsing error from the solr server.

An example could be something like

q=_query_:"{!dismax+qf%3D'title_textsv'+hl%3D'on'+hl.simple.pre%3D'@@@hl@@@'+hl.simple.post%3D'@@@endhl@@@'+hl.fl%3D'["title_textsv"]'}something"+_query_:"{!dismax+qf%3D'author_textsv'+hl%3D'on'+hl.simple.pre%3D'@@@hl@@@'+hl.simple.post%3D'@@@endhl@@@'+hl.fl%3D'["author_textsv"]'}something+else"

The problem is that highlighted fields are encoded as arrays, and hl.fl%3D'["title_textsv"] can't be parsed because quotes aren't escaped and because dismax syntax requires comma or space separated fields.

In this patch i just made sure arrays are correctly sent to the parser.

After the patch the above param becomes

q=_query_:"{!dismax+qf%3D'title_textsv'+hl%3D'on'+hl.simple.pre%3D'@@@hl@@@'+hl.simple.post%3D'@@@endhl@@@'+hl.fl%3D'title_textsv'}something"+_query_:"{!dismax+qf%3D'author_textsv'+hl%3D'on'+hl.simple.pre%3D'@@@hl@@@'+hl.simple.post%3D'@@@endhl@@@'+hl.fl%3D'author_textsv'}something+else"

Which doesn't give any parsing error.

What I find strange is that whenever i perform a standard query through my app's interface, I get highlighted results, but when i issue a query with different parameters on multiple fields, i don't get any highlight.

I suppose this could be a Solr problem, but I'm not sure about that.

(I didn't write any test because I couldn't get the test suite to work... )