jeudi 9 avril 2015

calling 'map' method on Searchkick::Results object returns always same order


Vote count:

0




I have a User model with following spec:



def search_data
{
full_name: full_name,
published: published,
sn: sn
}
end


Then I try to get ordered results on sn field. This is my query:


User.search("pablo", order: {sn: :asc}, fields: [:full_name], limit: 10)


Inspecting the resulting object reveals that it is working as expected:


User.search("pablo", order: {sn: :asc}, fields: [:full_name], limit: 10) gives:



#<Searchkick::Results:0x007feae41a3958
@klass=User,
@options={:page=>1, :per_page=>10, :padding=>0, :load=>true, :includes=>nil, :json=>false},
@response=
{"took"=>75,
"timed_out"=>false,
"_shards"=>{"total"=>1, "successful"=>1, "failed"=>0},
"hits"=>
{"total"=>5,
"max_score"=>nil,
"hits"=>
[{"_index"=>"users_production_20150409165753551", "_type"=>"user", "_id"=>"551598ba32663300160d0000", "_score"=>nil, "sort"=>[1]},
{"_index"=>"users_production_20150409165753551", "_type"=>"user", "_id"=>"54e3ba1d6538630003090000", "_score"=>nil, "sort"=>[2]}]}}>


You can see that first item in hits is the one supposed to be. If I run the query specifying descending order then first hits item is the one with sn 2. However, when I call #map method on Searchkick::Results object it always returns the same order not matter the order specified.


Is there anything I'm missing?


Thanks!



asked 2 mins ago







calling 'map' method on Searchkick::Results object returns always same order

Aucun commentaire:

Enregistrer un commentaire