diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 85658ca..a190f0f 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -109,7 +109,14 @@ module Searchkick if misspellings != false edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 - transpositions = (misspellings.is_a?(Hash) && misspellings[:transpositions] == true) ? {fuzzy_transpositions: true} : {} + transpositions = + if misspellings.is_a?(Hash) && misspellings[:transpositions] == true + {fuzzy_transpositions: true} + elsif below20? + {} + else + {fuzzy_transpositions: false} + end prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || 3 end @@ -148,7 +155,8 @@ module Searchkick if below12? {script_score: {script: "doc['count'].value"}} else - {field_value_factor: {field: "count"}} + conversions_count_field = below20? ? "count" : "#{conversions_field}.count" + {field_value_factor: {field: conversions_count_field}} end payload = { @@ -650,6 +658,10 @@ module Searchkick below_version?("1.4.0") end + def below20? + below_version?("2.0.0") + end + def below_version?(version) Gem::Version.new(Searchkick.server_version) < Gem::Version.new(version) end diff --git a/test/facets_test.rb b/test/facets_test.rb index 666ea73..0c7759e 100644 --- a/test/facets_test.rb +++ b/test/facets_test.rb @@ -4,6 +4,7 @@ require "active_support/core_ext" class TestFacets < Minitest::Test def setup + skip if elasticsearch2? super store [ {name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago}, diff --git a/test/highlight_test.rb b/test/highlight_test.rb index 6ca59ab..27b8f66 100644 --- a/test/highlight_test.rb +++ b/test/highlight_test.rb @@ -41,7 +41,7 @@ class TestHighlight < Minitest::Test json = { query: { match: { - _all: "cinema" + "name.analyzed" => "cinema" } }, highlight: { diff --git a/test/index_test.rb b/test/index_test.rb index d74f453..367900a 100644 --- a/test/index_test.rb +++ b/test/index_test.rb @@ -100,7 +100,7 @@ class TestIndex < Minitest::Test end def test_invalid_query - assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {}) } + assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {boom: true}) } end if defined?(ActiveRecord) diff --git a/test/routing_test.rb b/test/routing_test.rb index 1a9aa65..5430ed8 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -3,11 +3,13 @@ require_relative "test_helper" class TestRouting < Minitest::Test def test_routing_query + skip if elasticsearch2? query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) assert_equal query.params[:routing], "Dollar Tree" end def test_routing_mappings + skip if elasticsearch2? index_options = Store.searchkick_index.index_options assert_equal index_options[:mappings][:_default_][:_routing], {required: true, path: "name"} end diff --git a/test/test_helper.rb b/test/test_helper.rb index 4f0a444..a618bad 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,6 +17,10 @@ I18n.config.enforce_available_locales = true ActiveJob::Base.logger = nil if defined?(ActiveJob) +def elasticsearch2? + Searchkick.server_version.starts_with?("2.") +end + if defined?(Mongoid) def mongoid2? @@ -220,7 +224,7 @@ end class Store searchkick \ - routing: :name, + routing: elasticsearch2? ? false : "name", merge_mappings: true, mappings: { store: { -- libgit2 0.21.0