File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed
lib/elasticsearch/model/adapters
spec/elasticsearch/model/adapters Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,11 @@ def records
35
35
else
36
36
self . __send__ ( :exec_queries )
37
37
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
39
43
end if self
40
44
end
41
45
Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ class DummyClassForActiveRecord; end
95
95
96
96
before do
97
97
records . instance_variable_set ( :@records , records )
98
+ allow ( records ) . to receive ( :order_values ) . and_return ( [ ] )
98
99
end
99
100
100
101
it 'reorders the records based on hits order' do
@@ -111,6 +112,7 @@ class DummyClassForActiveRecord; end
111
112
before do
112
113
records . instance_variable_set ( :@records , records )
113
114
expect ( instance . records ) . to receive ( :order ) . and_return ( records )
115
+ allow ( records ) . to receive ( :order_values ) . and_return ( [ ] )
114
116
end
115
117
116
118
it 'reorders the records based on hits order' do
Original file line number Diff line number Diff line change @@ -231,6 +231,13 @@ def as_indexed_json(options = {})
231
231
end
232
232
end
233
233
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
+
234
241
should "allow dot access to response" do
235
242
response = Article . search query : { match : { title : { query : 'test' } } } ,
236
243
aggregations : {
You can’t perform that action at this time.
0 commit comments