Commit 5fcfd7d16490ab872ab45fb6032393f25009448f
1 parent
926a18e8
Exists in
master
and in
21 other branches
Elasticsearch 2.0 support - 3 tests failing
Showing
6 changed files
with
24 additions
and
5 deletions
Show diff stats
lib/searchkick/query.rb
... | ... | @@ -109,7 +109,14 @@ module Searchkick |
109 | 109 | |
110 | 110 | if misspellings != false |
111 | 111 | edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 |
112 | - transpositions = (misspellings.is_a?(Hash) && misspellings[:transpositions] == true) ? {fuzzy_transpositions: true} : {} | |
112 | + transpositions = | |
113 | + if misspellings.is_a?(Hash) && misspellings[:transpositions] == true | |
114 | + {fuzzy_transpositions: true} | |
115 | + elsif below20? | |
116 | + {} | |
117 | + else | |
118 | + {fuzzy_transpositions: false} | |
119 | + end | |
113 | 120 | prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 |
114 | 121 | max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || 3 |
115 | 122 | end |
... | ... | @@ -148,7 +155,8 @@ module Searchkick |
148 | 155 | if below12? |
149 | 156 | {script_score: {script: "doc['count'].value"}} |
150 | 157 | else |
151 | - {field_value_factor: {field: "count"}} | |
158 | + conversions_count_field = below20? ? "count" : "#{conversions_field}.count" | |
159 | + {field_value_factor: {field: conversions_count_field}} | |
152 | 160 | end |
153 | 161 | |
154 | 162 | payload = { |
... | ... | @@ -650,6 +658,10 @@ module Searchkick |
650 | 658 | below_version?("1.4.0") |
651 | 659 | end |
652 | 660 | |
661 | + def below20? | |
662 | + below_version?("2.0.0") | |
663 | + end | |
664 | + | |
653 | 665 | def below_version?(version) |
654 | 666 | Gem::Version.new(Searchkick.server_version) < Gem::Version.new(version) |
655 | 667 | end | ... | ... |
test/facets_test.rb
... | ... | @@ -4,6 +4,7 @@ require "active_support/core_ext" |
4 | 4 | class TestFacets < Minitest::Test |
5 | 5 | |
6 | 6 | def setup |
7 | + skip if elasticsearch2? | |
7 | 8 | super |
8 | 9 | store [ |
9 | 10 | {name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago}, | ... | ... |
test/highlight_test.rb
test/index_test.rb
... | ... | @@ -100,7 +100,7 @@ class TestIndex < Minitest::Test |
100 | 100 | end |
101 | 101 | |
102 | 102 | def test_invalid_query |
103 | - assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {}) } | |
103 | + assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {boom: true}) } | |
104 | 104 | end |
105 | 105 | |
106 | 106 | if defined?(ActiveRecord) | ... | ... |
test/routing_test.rb
... | ... | @@ -3,11 +3,13 @@ require_relative "test_helper" |
3 | 3 | class TestRouting < Minitest::Test |
4 | 4 | |
5 | 5 | def test_routing_query |
6 | + skip if elasticsearch2? | |
6 | 7 | query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) |
7 | 8 | assert_equal query.params[:routing], "Dollar Tree" |
8 | 9 | end |
9 | 10 | |
10 | 11 | def test_routing_mappings |
12 | + skip if elasticsearch2? | |
11 | 13 | index_options = Store.searchkick_index.index_options |
12 | 14 | assert_equal index_options[:mappings][:_default_][:_routing], {required: true, path: "name"} |
13 | 15 | end | ... | ... |
test/test_helper.rb
... | ... | @@ -17,6 +17,10 @@ I18n.config.enforce_available_locales = true |
17 | 17 | |
18 | 18 | ActiveJob::Base.logger = nil if defined?(ActiveJob) |
19 | 19 | |
20 | +def elasticsearch2? | |
21 | + Searchkick.server_version.starts_with?("2.") | |
22 | +end | |
23 | + | |
20 | 24 | if defined?(Mongoid) |
21 | 25 | |
22 | 26 | def mongoid2? |
... | ... | @@ -220,7 +224,7 @@ end |
220 | 224 | |
221 | 225 | class Store |
222 | 226 | searchkick \ |
223 | - routing: :name, | |
227 | + routing: elasticsearch2? ? false : "name", | |
224 | 228 | merge_mappings: true, |
225 | 229 | mappings: { |
226 | 230 | store: { | ... | ... |