Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Total number of documents in pysolr

How can I get the total number of documents matching the given query. I have use the query below:

result = solr.search('ad_id : 20')
print(len(result))

Since the default returning value is '10', the output is only 10, but the count is 4000. How can I get the total number of counts?

like image 634
Manish Ojha Avatar asked Jan 03 '23 10:01

Manish Ojha


1 Answers

The results object from pysolr has a hits property that contains the total number of hits, regardless of how many documents being returned. This is named numFound in the raw response from Solr.

Your solution isn't really suitable for anything with a larger dataset, since it requires you to retrieve all the documents, even if you don't need them or want to show their content.

like image 163
MatsLindh Avatar answered Jan 28 '23 09:01

MatsLindh