Isaac
Isaac

Reputation: 1401

Django haystack with Solr - how to specify GET parameters?

I'm using django_haystack with Solr 4.9. I've amended the /select request handler so that all requests use dismax by default.

The problem is that sometimes I would like to query specific fields, but I can't find a way to get the SearchQuerySet api to get it to play nicely with dismax. So basically I want to send the following (or equivalent) request to Solr:q=hello&qf=content_auto

I've tried the following aproaches:

Standard Api

SearchQuerySet().filter(content_auto='hello') 

# understandably results in the following being sent to solr:
q=content_auto:hello

AltParser

query = AltParser('dismax', 'hello', qf="content_auto")
sqs = SearchQuerySet().filter(content=query)

# Results in
q=(_query_:"{!dismax+qf%3Dcontent_auto}hello")

Raw

query = Raw('hello&qf=content_auto')

# results in
q=hello%26qf%3Dcontent_auto

The last approach was so close, but since it escaped the = and & it doesn't seem to process the query correctly.

What is the best approach to dealing with this? I have no need for non-dismax querying so it would be preferable to keep the /select request handler the same rather than having to wrap every query in a Raw or AltParser.

Upvotes: 1

Views: 301

Answers (1)

Isaac
Isaac

Reputation: 1401

In short, the answer is that it can't be done without creating a custom backend and SearchQuerySet. In the end I had to just revert back to a standard configuration and specifying dismax with an AltParser, slightly annoying because it affects your spelling suggestions.

Upvotes: 2

Related Questions