如何獲得與給定查詢匹配的文檔總數。我用下面的查詢:pysolr中的文檔總數
result = solr.search('ad_id : 20')
print(len(result))
由於默認返回值是「10」,輸出的是隻有10,但數量是4000我怎樣才能得到計數的總數是多少?
如何獲得與給定查詢匹配的文檔總數。我用下面的查詢:pysolr中的文檔總數
result = solr.search('ad_id : 20')
print(len(result))
由於默認返回值是「10」,輸出的是隻有10,但數量是4000我怎樣才能得到計數的總數是多少?
終於得到了答案:
新增rows=1000000
在查詢結束。
result = solr.search('ad_id : 20', rows=1000000)
但是,如果行是超過這個數量應該在查詢中改變更大。這可能是一個不好的解決方案,但工作。 如果有人有更好的解決方案,請回復。
results object from pysolr has a hits
property that contains the total number of hits,無論返回多少文檔。這在Solr的原始響應中被命名爲numFound
。
您的解決方案並不適合任何大型數據集,因爲它需要您檢索所有文檔,即使您不需要它們或者不想顯示其內容。
計數存儲在numFound變量中。請使用以下代碼:
result = solr.search('ad_id : 20')
print(result.raw_response['response']['numFound'])
這與結果中的'hits'屬性有何不同?沒有必要使用原始響應。 – MatsLindh