Commit 9b11e5b3090378b76754ccd7a3d2b0ddd5b97033

Authored by Andrew Kane
2 parents 0cd98443 56d277c7

Merged

README.md
... ... @@ -757,6 +757,12 @@ Product.enable_search_callbacks # or use Searchkick.enable_callbacks for all mod
757 757 Product.reindex
758 758 ```
759 759  
  760 +Change the #search method name in `config/initializers/searchkick.rb`
  761 +
  762 +```ruby
  763 +Searchkick.search_method_name = :lookup
  764 +```
  765 +
760 766 Eager load associations
761 767  
762 768 ```ruby
... ...
lib/searchkick.rb
... ... @@ -6,7 +6,6 @@ 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"
... ... @@ -17,6 +16,14 @@ module Searchkick
17 16 class UnsupportedVersionError < StandardError; end
18 17 class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end
19 18  
  19 + def self.search_method_name=(_search_method_name)
  20 + @search_method_name ||= _search_method_name
  21 + end
  22 +
  23 + def self.search_method_name
  24 + @search_method_name || :search
  25 + end
  26 +
20 27 def self.client
21 28 @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"])
22 29 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/similar.rb
... ... @@ -12,7 +12,7 @@ module Searchkick
12 12 options[:where][:_id][:not] = id.to_s
13 13 options[:limit] ||= 10
14 14 options[:similar] = true
15   - self.class.search(like_text, options)
  15 + self.class.send(Searchkick.search_method_name, like_text, options)
16 16 end
17 17  
18 18 end
... ...