SearchKick 获取总结果数
SearchKick get total results count
我正在使用 SearchKick
搜索数据。我正在执行分页。在这种情况下我如何获得总结果数:
我的 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
它returns我说错了:
undefined method
响应'`
Searchkick 提供了一个 #total_count
方法来计算响应的总点击数:
def total_count
response["hits"]["total"]
end
alias_method :total_entries, :total_count
在 searchkick (0.9.0) 中是:
response.total_count
试试这个:-
data = Model_name.search '*'
data.results.count
我正在使用 SearchKick
搜索数据。我正在执行分页。在这种情况下我如何获得总结果数:
我的 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
它returns我说错了:
undefined method
响应'`
Searchkick 提供了一个 #total_count
方法来计算响应的总点击数:
def total_count
response["hits"]["total"]
end
alias_method :total_entries, :total_count
在 searchkick (0.9.0) 中是:
response.total_count
试试这个:-
data = Model_name.search '*'
data.results.count