I have a requirement where I want to get results based on the order of IDs that i pass to sphinx:
I did sorting and filtering with ruby and then find order of user_ids to be
user_ids = [1, 3, 2]
Now, I want to apply search on top of this:
User.search_for_ids("Test", {:with => {:page => params[:page], :per_page => 25, :sphinx_internal_id => user_ids}, :sql => {:order => "field(id,#{user_ids.join(',')})"}})
I see that we can pass :sql => :order in options when we need to sort on sql. But that does not give me the result in the expected sorting order.
User.where(:id => [1, 2, 3]).order("field(id,#{user_ids.join(',')})")
gives me proper results as expected
Please correct me if i am doing anything wrong here.Is there a way to preserve the order with respect to user_ids ? Any help is much appreciated.