2

两个问题合并为一个问题:

为什么 haystack auto_query 向 solr 发送两个请求并转义 : 字符?

我已经按照手册中的说明设置了 haystack,一切运行正常,但是每当我跟踪我的 solr 日志时,如果来自 haystack(用于一个查询),我会看到两个请求,如果来自管理页面,则会看到一个请求:

所以我查询:

title:ong

从干草堆我得到:

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

而从管理部分:

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

haystack请求中存在额外的参数,这是可以理解的。

如您所见, q 参数是相同的。

几乎一样:任何人都可以说出为什么 haystack auto_query 会转义 : 字符并发出两个请求?

我相信,因为 : 被转义,Solr 不会仅从字段“title”返回“ong”,而是搜索 title\:ong 作为字符串,当然它不会返回任何内容。

4

1 回答 1

2

我刚刚发现它为什么会逃脱冒号字符。那是因为 AutoQuery 默认会清理它们

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))

仍在寻找为什么它会发出两个请求...

最新的编辑:

由于这个位,它发出了两个请求

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

在 SearchView().create_response()

于 2012-07-12T13:09:56.057 回答