Count total search objects count in template using django-haystack
Asked Answered
S

3

10

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.

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.

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.

Sustainer answered 24/11, 2011 at 18:54 Comment(0)
J
33

Haystack uses the standard django pagination: 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 }}

Jepson answered 29/11, 2011 at 15:26 Comment(0)
E
6

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

Results {{ page.start_index }} - {{ page.end_index }} of {{ page.paginator.count }}
Easter answered 29/3, 2013 at 15:59 Comment(0)
D
0
{{ page.object_list | length }}
Dryly answered 27/11, 2011 at 21:57 Comment(1)
this only tells you how many objects are on this page of results. It doesn't tell you how many results were returned in total (ex: Showing 20 of 53 - Showing {{ page.object_list | length }} of {{ HOW DO YOU GET THIS NUMBER OVER HERE}})Jepson

© 2022 - 2024 — McMap. All rights reserved.