Commit cb3f8cb8087f77bc7276bbd5000c491481f95c76

Authored by Andrew Kane
2 parents 0cd98443 36916f44

Merge branch 'coryodaniel-master'

CHANGELOG.md
  1 +## 0.8.1 [unreleased]
  2 +
  3 +- Added `search_method_name` option
  4 +
1 5 ## 0.8.0
2 6  
3 7 - Added support for Elasticsearch 1.2
... ...
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` [master]
  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,11 @@ module Searchkick
17 16 class UnsupportedVersionError < StandardError; end
18 17 class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end
19 18  
  19 + class << self
  20 + attr_accessor :search_method_name
  21 + end
  22 + self.search_method_name = :search
  23 +
20 24 def self.client
21 25 @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"])
22 26 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 = nil, 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
... ...