File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
lib/elasticsearch/model/adapters Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,11 @@ def records
3535 else
3636 self . __send__ ( :exec_queries )
3737 end
38- @records . sort_by { |record | hits . index { |hit | hit [ '_id' ] . to_s == record . id . to_s } }
38+ if !self . order_values . present?
39+ @records . sort_by { |record | hits . index { |hit | hit [ '_id' ] . to_s == record . id . to_s } }
40+ else
41+ @records
42+ end
3943 end if self
4044 end
4145
Original file line number Diff line number Diff line change @@ -231,6 +231,13 @@ def as_indexed_json(options = {})
231231 end
232232 end
233233
234+ should "allow ordering following any method chain in SQL" do
235+ if defined? ( ::ActiveRecord ) && ::ActiveRecord ::VERSION ::MAJOR >= 4
236+ response = Article . search query : { match : { title : { query : 'test' } } }
237+ assert_equal 'Testing Coding' , response . records . distinct . order ( id : :desc ) . first . title
238+ end
239+ end
240+
234241 should "allow dot access to response" do
235242 response = Article . search query : { match : { title : { query : 'test' } } } ,
236243 aggregations : {
You can’t perform that action at this time.
0 commit comments