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.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
tejinderss
  • 1,612
  • 17
  • 20

3 Answers3

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

Below the Radar
  • 7,321
  • 11
  • 63
  • 142
Francis Yaconiello
  • 10,829
  • 2
  • 35
  • 54
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 }}
mynameistechno
  • 3,526
  • 1
  • 37
  • 32
0
{{ page.object_list | length }}
stema
  • 90,351
  • 20
  • 107
  • 135
soField
  • 2,536
  • 9
  • 36
  • 44
  • 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}}) – Francis Yaconiello Nov 29 '11 at 15:17