Commit f7fe8ee765bf6ad311d0410a9adf4bc67d1ba9b6
1 parent
95672b1c
Exists in
master
and in
21 other branches
added Searchkick.search_method_name to allow for changing the search method when…
… it conflicts with other gems
Showing
4 changed files
with
16 additions
and
17 deletions
Show diff stats
lib/searchkick.rb
... | ... | @@ -6,14 +6,20 @@ require "searchkick/index" |
6 | 6 | require "searchkick/reindex" |
7 | 7 | require "searchkick/results" |
8 | 8 | require "searchkick/query" |
9 | -require "searchkick/search" | |
10 | 9 | require "searchkick/similar" |
11 | 10 | require "searchkick/model" |
12 | 11 | require "searchkick/tasks" |
13 | 12 | require "searchkick/logging" if defined?(Rails) |
14 | 13 | |
15 | 14 | module Searchkick |
15 | + def self.search_method_name=(_search_method_name) | |
16 | + @search_method_name ||= _search_method_name | |
17 | + end | |
16 | 18 | |
19 | + def self.search_method_name | |
20 | + @search_method_name || :search | |
21 | + end | |
22 | + | |
17 | 23 | def self.client |
18 | 24 | @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"]) |
19 | 25 | end | ... | ... |
lib/searchkick/model.rb
... | ... | @@ -19,7 +19,14 @@ module Searchkick |
19 | 19 | Searchkick::Index.new(index) |
20 | 20 | end |
21 | 21 | |
22 | - extend Searchkick::Search | |
22 | + define_singleton_method(Searchkick.search_method_name) do |term, options={}| | |
23 | + query = Searchkick::Query.new(self, term, options) | |
24 | + if options[:execute] == false | |
25 | + query | |
26 | + else | |
27 | + query.execute | |
28 | + end | |
29 | + end | |
23 | 30 | extend Searchkick::Reindex |
24 | 31 | include Searchkick::Similar |
25 | 32 | ... | ... |
lib/searchkick/search.rb
lib/searchkick/similar.rb