Commit d44d2f6319e9a0fd710c194edbbb32d9202b88f6
1 parent
309d0b6b
Exists in
master
and in
17 other branches
Added support for routing to similar method - closes #1249
Showing
4 changed files
with
14 additions
and
7 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/index.rb
... | ... | @@ -91,11 +91,12 @@ module Searchkick |
91 | 91 | alias_method :swap, :promote |
92 | 92 | |
93 | 93 | def retrieve(record) |
94 | - client.get( | |
95 | - index: name, | |
96 | - type: document_type(record), | |
97 | - id: search_id(record) | |
98 | - )["_source"] | |
94 | + record_data = RecordData.new(self, record).record_data | |
95 | + | |
96 | + # remove underscore | |
97 | + get_options = Hash[record_data.map { |k, v| [k.to_s.sub(/\A_/, "").to_sym, v] }] | |
98 | + | |
99 | + client.get(get_options)["_source"] | |
99 | 100 | end |
100 | 101 | |
101 | 102 | def all_indices(unaliased: false) | ... | ... |
lib/searchkick/record_data.rb
... | ... | @@ -39,8 +39,6 @@ module Searchkick |
39 | 39 | @routing_key ||= Searchkick.server_below?("6.0.0") ? :_routing : :routing |
40 | 40 | end |
41 | 41 | |
42 | - private | |
43 | - | |
44 | 42 | def record_data |
45 | 43 | data = { |
46 | 44 | _index: index.name, |
... | ... | @@ -51,6 +49,8 @@ module Searchkick |
51 | 49 | data |
52 | 50 | end |
53 | 51 | |
52 | + private | |
53 | + | |
54 | 54 | def search_data(method_name = nil) |
55 | 55 | partial_reindex = !method_name.nil? |
56 | 56 | ... | ... |
test/similar_test.rb
... | ... | @@ -25,4 +25,9 @@ class SimilarTest < Minitest::Test |
25 | 25 | store_names ["1% Organic Milk", "2% Organic Milk", "Fat Free Organic Milk", "Popcorn"] |
26 | 26 | assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"], order: ["name"], per_page: 1).map(&:name) |
27 | 27 | end |
28 | + | |
29 | + def test_routing | |
30 | + store_names ["Test"], Store | |
31 | + assert_equal [], Store.first.similar(fields: ["name"]).map(&:name) | |
32 | + end | |
28 | 33 | end | ... | ... |