使用django-haystack计算模板中的搜索对象总数

时间:2021-12-16 03:31:16

I am using django haystack with xapian as the backend search engine. I am using FacetedSearchView and FacetedSearchForm for faceting over the search. I have passed searchqueryset to the FacetSearchView in my urls.py file.

我使用django haystack和xapian作为后端搜索引擎。我正在使用FacetedSearchView和FacetedSearchForm进行搜索。我已经将searchqueryset传递给FacetSearchView在我的url中。py文件。

But the problem is I cannot access that searchqueryset in template. All I want to do is count the number of objects in searchqueryset found.

但是问题是我不能访问模板中的searchqueryset。我要做的就是计算在searchqueryset中找到的对象的数量。

In shell I could achieve it using SearchQuerySet().filter(content="foo").count(), how can I do that similarly in the template? Please guide. I want the total number of objects matching the search.

在shell中,我可以使用SearchQuerySet().filter(content="foo").count()来实现它,我如何在模板中实现这一点呢?请指导。我想要匹配搜索的对象的总数。

3 个解决方案

#1


30  

Haystack uses the standard django pagination: https://docs.djangoproject.com/en/dev/topics/pagination/

Haystack使用了标准的django分页:https://docs.djangoproject.com/en/dev/topics/pagination/

Showing {{ page.object_list|length }} of {{ page.paginator.count }} Results on Page {{ page.number }} of {{ page.paginator.num_pages }}

{ {页面。{page.paginator的object_list|length}。计数}在页{页上的结果。{page.paginator的number}。num_pages } }

#2


5  

If you want to show the result range instead of page number, e.g. "Results 21-40 of 1001", You can do

如果你想显示结果范围而不是页码,例如“1001的结果21-40”,你可以做到

Results {{ page.start_index }} - {{ page.end_index }} of {{ page.paginator.count }}

#3


0  

{{ page.object_list | length }}

#1


30  

Haystack uses the standard django pagination: https://docs.djangoproject.com/en/dev/topics/pagination/

Haystack使用了标准的django分页:https://docs.djangoproject.com/en/dev/topics/pagination/

Showing {{ page.object_list|length }} of {{ page.paginator.count }} Results on Page {{ page.number }} of {{ page.paginator.num_pages }}

{ {页面。{page.paginator的object_list|length}。计数}在页{页上的结果。{page.paginator的number}。num_pages } }

#2


5  

If you want to show the result range instead of page number, e.g. "Results 21-40 of 1001", You can do

如果你想显示结果范围而不是页码,例如“1001的结果21-40”,你可以做到

Results {{ page.start_index }} - {{ page.end_index }} of {{ page.paginator.count }}

#3


0  

{{ page.object_list | length }}