我正在使用SearchKick搜索数据。我正在表演分页。在这种情况下,如何获得结果总数:
我的搜索结果:
#<Searchkick::Results:0x007faeeef8ed88
@facets=nil,
@max_score=0.0,
@options=
{:load=>true,
:payload=>
{:query=>{:match_all=>{}},
:size=>20,
:from=>0,
:sort=>{"created_at"=>:desc},
:filter=>{:and=>[{:term=>{"sub_category_id"=>2}}]},
:fields=>[]},
:size=>20,
:from=>0,
:term=>"*"},
@response=
{"took"=>4,
"timed_out"=>false,
"_shards"=>{"total"=>5, "successful"=>5, "failed"=>0},
"hits"=>
{"total"=>1925,
"max_score"=>nil,
"hits"=>
[{"_index"=>"products_..", "_type"=>"product", "_id"=>"..", "_score"=>nil, "sort"=>[..]},....]}},
@results=
[#<Product>,...]....还有一件事我不能做:
SearchKickResult.response它会返回我说的错误:
undefined method响应‘’
发布于 2015-04-28 13:30:21
Searchkick提供了一个#total_count方法,用于统计响应的总命中次数:
def total_count
response["hits"]["total"]
end
alias_method :total_entries, :total_count发布于 2015-06-17 11:53:32
在搜索(0.9.0)中,它是:response.total_count
发布于 2021-10-29 12:58:36
试试这个:-
data = Model_name.search '*‘
data.results.count
https://stackoverflow.com/questions/29920922
复制相似问题