2
votes

Two issues bundled into one question:

Why does haystack auto_query send two requests to solr and escapes the : character ?

I've set up haystack as it is written in the manual, everything running OK, but whenever I tail my solr log I see two requests if coming from haystack (for one query) and one request if coming from the admin page:

So I query:

title:ong

From Haystack I get:

Jul 12, 2012 2:37:30 PM org.apache.solr.core.SolrCore execute
INFO: [collection1] webapp=/solr path=/select/ params={spellcheck=true&sort=cand+desc&fl=*+score&start=0&q=(title\:ong)&spellcheck.count=1&spellcheck.collate=true&wt=json&fq=django_ct:(ads.model1+OR+ads.model2+OR+ads.model3)&rows=1} hits=0 status=0 QTime=21
Jul 12, 2012 2:37:30 PM org.apache.solr.core.SolrCore execute
INFO: [collection1] webapp=/solr path=/select/ params={spellcheck=true&sort=cand+desc&fl=*+score&start=0&q=(title\:ong)&spellcheck.count=1&spellcheck.collate=true&wt=json&fq=django_ct:(ads.model1+OR+ads.model2+OR+ads.model3)&rows=0} hits=0 status=0 QTime=23

while from the admin section:

Jul 12, 2012 2:42:35 PM org.apache.solr.core.SolrCore execute
INFO: [collection1] webapp=/solr path=/select params={spellcheck=true&indent=true&q=title:ong&wt=json} hits=2 status=0 QTime=12

Extra parameters exist in haystack requests, that is understandable.

As you can see the q parameter is the same.

Well almost the same: anyone can tell why haystack auto_query escapes the : character and sends out two requests?

I believe that, because : is escaped, Solr doesnt return "ong" just from the field "title" and searches for title\:ong as a string, of course it doesnt return anything.

1

1 Answers

2
votes

I just found out why it escapes the colon char. Thats because AutoQuery cleans them by default

class AutoQuery(BaseInput):
....
def prepare(self, query_obj):
....
    for token in tokens:
        if not token:
            continue
        if token in exacts:
            query_bits.append(Exact(token, clean=True).prepare(query_obj))
        elif token.startswith('-') and len(token) > 1:
            # This might break Xapian. Check on this.
            query_bits.append(Not(token[1:]).prepare(query_obj))
        else:
            query_bits.append(Clean(token).prepare(query_obj))

Still looking why it fires out two requests ...

The latest edit ever:

It sends out two requests because of this bit

    if self.results and hasattr(self.results, 'query') and self.results.query.backend.include_spelling:
        context['suggestion'] = self.form.get_suggestion()

In SearchView().create_response()