我正在使用Haystack 2.4和SOLR 4. *并尝试进行分面搜索。这是我的模板:
<h4>By Author</h4>
<div>
<dl>
{% if facets.fields.author %}
<dt>Author</dt>
{# Provide only the top 5 authors #}
{% for author in facets.fields.author|slice:":5" %}
<dd><a href="{{ request.get_full_path }}&selected_facets=author_exact:{{ author.0|urlencode }}">{{ author.0 }}</a> ({{ author.1 }})</dd>
{% endfor %}
{% else %}
<p>No author facets.</p>
{% endif %}
</dl>
但它只显示最高级别的结果:
author1 (20)
当我只是单击author1进行深入分析时,没有任何内容显示。它只是把网址加起来 http://localhost:8000/search/?q=test1&selected_facets=author_exact:author1&selected_facets=author_exact:author1&selected_facets=author_exact:author1
有人有任何想法吗? 谢谢!
答案 0 :(得分:0)
它似乎与我的url.py配置有关。我试着用
urlpatterns = patterns('haystack.views',
url(r'^$', FacetedSearchView(form_class=FacetedSearchForm, facet_fields=['author']), name='haystack_search'), )
如haystack faceted search documentation http://django-haystack.readthedocs.org/en/latest/faceting.html
中所述但我在意外关键字facet_fileds
上收到错误。我仔细检查了haystack FacetedSearchView
和SearchView
的init。它似乎没有facet_fields
的init参数。然后我切换到以下方式,这对我来说很好。
faceted_sqs = SearchQuerySet().facet('author')
urlpatterns = patterns('haystack.views',url(r'^$',FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=faceted_sqs), name='haystack_search'), )
如果我有什么不妥,请指出。谢谢!