Commit f22aa73d81b2e6d978dbc1cb6526ce82af4df709
1 parent
2142c8be
Exists in
master
and in
19 other branches
Use Searchkick.search internally for model search
Showing
3 changed files
with
13 additions
and
2 deletions
Show diff stats
lib/searchkick.rb
... | ... | @@ -81,7 +81,17 @@ module Searchkick |
81 | 81 | end |
82 | 82 | |
83 | 83 | def self.search(term = "*", **options, &block) |
84 | - query = Searchkick::Query.new(nil, term, options) | |
84 | + klass = options[:model] | |
85 | + | |
86 | + # TODO add in next major version | |
87 | + # if !klass | |
88 | + # index_name = Array(options[:index_name]) | |
89 | + # if index_name.size == 1 && index_name.first.respond_to?(:searchkick_index) | |
90 | + # klass = index_name.first | |
91 | + # end | |
92 | + # end | |
93 | + | |
94 | + query = Searchkick::Query.new(klass, term, options.except(:model)) | |
85 | 95 | block.call(query.body) if block |
86 | 96 | if options[:execute] == false |
87 | 97 | query | ... | ... |
lib/searchkick/index.rb
... | ... | @@ -159,6 +159,7 @@ module Searchkick |
159 | 159 | |
160 | 160 | # search |
161 | 161 | |
162 | + # TODO remove in next major version | |
162 | 163 | def search_model(searchkick_klass, term = "*", **options, &block) |
163 | 164 | query = Searchkick::Query.new(searchkick_klass, term, options) |
164 | 165 | yield(query.body) if block | ... | ... |
lib/searchkick/model.rb
... | ... | @@ -26,7 +26,7 @@ module Searchkick |
26 | 26 | |
27 | 27 | class << self |
28 | 28 | def searchkick_search(term = "*", **options, &block) |
29 | - searchkick_index.search_model(self, term, options, &block) | |
29 | + Searchkick.search(term, {model: self}.merge(options), &block) | |
30 | 30 | end |
31 | 31 | alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name |
32 | 32 | ... | ... |