File tree 2 files changed +8
-2
lines changed
lib/elasticsearch/model/adapters
2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,10 @@ def records
26
26
# by redefining `to_a`, unless the user has called `order()`
27
27
#
28
28
sql_records . instance_exec ( response . response [ 'hits' ] [ 'hits' ] ) do |hits |
29
- define_singleton_method :to_a do
29
+ ar_records_method_name = :to_a
30
+ ar_records_method_name = :records if defined? ( ::ActiveRecord ) && ::ActiveRecord ::VERSION ::MAJOR >= 5
31
+
32
+ define_singleton_method ( ar_records_method_name ) do
30
33
if defined? ( ::ActiveRecord ) && ::ActiveRecord ::VERSION ::MAJOR >= 4
31
34
self . load
32
35
else
Original file line number Diff line number Diff line change @@ -104,7 +104,10 @@ def as_indexed_json(options = {})
104
104
end
105
105
106
106
should "preserve the search results order for records" do
107
- response = Article . search ( 'title:code' )
107
+ response = Article . search query : { match : { title : 'code' } } , sort : { clicks : :desc }
108
+
109
+ assert_equal response . records [ 0 ] . clicks , 3
110
+ assert_equal response . records [ 1 ] . clicks , 2
108
111
109
112
response . records . each_with_hit do |r , h |
110
113
assert_equal h . _id , r . id . to_s
You can’t perform that action at this time.
0 commit comments