Commit 36916f445fe94232c40f5ffc9b981fb65ab90370

Authored by Andrew Kane
1 parent 9b11e5b3

Updated search_method_name option

  1 +## 0.8.1 [unreleased]
  2 +
  3 +- Added `search_method_name` option
  4 +
1 ## 0.8.0 5 ## 0.8.0
2 6
3 - Added support for Elasticsearch 1.2 7 - Added support for Elasticsearch 1.2
@@ -757,7 +757,7 @@ Product.enable_search_callbacks # or use Searchkick.enable_callbacks for all mod @@ -757,7 +757,7 @@ Product.enable_search_callbacks # or use Searchkick.enable_callbacks for all mod
757 Product.reindex 757 Product.reindex
758 ``` 758 ```
759 759
760 -Change the #search method name in `config/initializers/searchkick.rb` 760 +Change the search method name in `config/initializers/searchkick.rb` [master]
761 761
762 ```ruby 762 ```ruby
763 Searchkick.search_method_name = :lookup 763 Searchkick.search_method_name = :lookup
lib/searchkick.rb
@@ -16,13 +16,10 @@ module Searchkick @@ -16,13 +16,10 @@ module Searchkick
16 class UnsupportedVersionError < StandardError; end 16 class UnsupportedVersionError < StandardError; end
17 class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end 17 class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end
18 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 19 + class << self
  20 + attr_accessor :search_method_name
25 end 21 end
  22 + self.search_method_name = :search
26 23
27 def self.client 24 def self.client
28 @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"]) 25 @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"])
lib/searchkick/model.rb
@@ -19,7 +19,7 @@ module Searchkick @@ -19,7 +19,7 @@ module Searchkick
19 Searchkick::Index.new(index) 19 Searchkick::Index.new(index)
20 end 20 end
21 21
22 - define_singleton_method(Searchkick.search_method_name) do |term, options={}| 22 + define_singleton_method(Searchkick.search_method_name) do |term = nil, options={}|
23 query = Searchkick::Query.new(self, term, options) 23 query = Searchkick::Query.new(self, term, options)
24 if options[:execute] == false 24 if options[:execute] == false
25 query 25 query