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