Commit cb3f8cb8087f77bc7276bbd5000c491481f95c76
Exists in
master
and in
21 other branches
Merge branch 'coryodaniel-master'
Showing
5 changed files
with
24 additions
and
3 deletions
Show diff stats
CHANGELOG.md
README.md
@@ -757,6 +757,12 @@ Product.enable_search_callbacks # or use Searchkick.enable_callbacks for all mod | @@ -757,6 +757,12 @@ 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` [master] | ||
761 | + | ||
762 | +```ruby | ||
763 | +Searchkick.search_method_name = :lookup | ||
764 | +``` | ||
765 | + | ||
760 | Eager load associations | 766 | Eager load associations |
761 | 767 | ||
762 | ```ruby | 768 | ```ruby |
lib/searchkick.rb
@@ -6,7 +6,6 @@ require "searchkick/index" | @@ -6,7 +6,6 @@ require "searchkick/index" | ||
6 | require "searchkick/reindex" | 6 | require "searchkick/reindex" |
7 | require "searchkick/results" | 7 | require "searchkick/results" |
8 | require "searchkick/query" | 8 | require "searchkick/query" |
9 | -require "searchkick/search" | ||
10 | require "searchkick/similar" | 9 | require "searchkick/similar" |
11 | require "searchkick/model" | 10 | require "searchkick/model" |
12 | require "searchkick/tasks" | 11 | require "searchkick/tasks" |
@@ -17,6 +16,11 @@ module Searchkick | @@ -17,6 +16,11 @@ module Searchkick | ||
17 | class UnsupportedVersionError < StandardError; end | 16 | class UnsupportedVersionError < StandardError; end |
18 | class InvalidQueryError < Elasticsearch::Transport::Transport::Errors::BadRequest; end | 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 | def self.client | 24 | def self.client |
21 | @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"]) | 25 | @client ||= Elasticsearch::Client.new(url: ENV["ELASTICSEARCH_URL"]) |
22 | end | 26 | end |
lib/searchkick/model.rb
@@ -19,7 +19,14 @@ module Searchkick | @@ -19,7 +19,14 @@ module Searchkick | ||
19 | Searchkick::Index.new(index) | 19 | Searchkick::Index.new(index) |
20 | end | 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 | extend Searchkick::Reindex | 30 | extend Searchkick::Reindex |
24 | include Searchkick::Similar | 31 | include Searchkick::Similar |
25 | 32 |
lib/searchkick/similar.rb
@@ -12,7 +12,7 @@ module Searchkick | @@ -12,7 +12,7 @@ module Searchkick | ||
12 | options[:where][:_id][:not] = id.to_s | 12 | options[:where][:_id][:not] = id.to_s |
13 | options[:limit] ||= 10 | 13 | options[:limit] ||= 10 |
14 | options[:similar] = true | 14 | options[:similar] = true |
15 | - self.class.search(like_text, options) | 15 | + self.class.send(Searchkick.search_method_name, like_text, options) |
16 | end | 16 | end |
17 | 17 | ||
18 | end | 18 | end |