Commit 90275986b9e4488f0773315aa1a3cc33269ac824

Authored by Andrew Kane
1 parent 42095ac8

Fixed tests for OpenSearch 2.0.0-rc1 [skip ci]

README.md
... ... @@ -2038,7 +2038,7 @@ Turn on misspellings after a certain number of characters
2038 2038 Product.search("api", misspellings: {prefix_length: 2}) # api, apt, no ahi
2039 2039 ```
2040 2040  
2041   -**Note:** With this option, if the query length is the same as `prefix_length`, misspellings are turned off with Elasticsearch 7 and OpenSearch
  2041 +**Note:** With this option, if the query length is the same as `prefix_length`, misspellings are turned off with Elasticsearch 7 and OpenSearch 1
2042 2042  
2043 2043 ```ruby
2044 2044 Product.search("ah", misspellings: {prefix_length: 2}) # ah, no aha
... ...
lib/searchkick.rb
... ... @@ -135,8 +135,9 @@ module Searchkick
135 135 @opensearch
136 136 end
137 137  
138   - def self.server_below?(version)
139   - server_version = opensearch? ? "7.10.2" : self.server_version
  138 + # TODO always check true version in Searchkick 6
  139 + def self.server_below?(version, true_version = false)
  140 + server_version = !true_version && opensearch? ? "7.10.2" : self.server_version
140 141 Gem::Version.new(server_version.split("-")[0]) < Gem::Version.new(version.split("-")[0])
141 142 end
142 143  
... ...
test/misspellings_test.rb
... ... @@ -13,7 +13,7 @@ class MisspellingsTest &lt; Minitest::Test
13 13  
14 14 def test_prefix_length
15 15 store_names ["ap", "api", "apt", "any", "nap", "ah", "ahi"]
16   - if Searchkick.server_below?("8.0.0")
  16 + if prefix_length_misspellings_off?
17 17 assert_search "ap", ["ap"], misspellings: {prefix_length: 2}
18 18 else
19 19 assert_search "ap", ["ap", "api", "apt"], misspellings: {prefix_length: 2}
... ... @@ -23,7 +23,7 @@ class MisspellingsTest &lt; Minitest::Test
23 23  
24 24 def test_prefix_length_operator
25 25 store_names ["ap", "api", "apt", "any", "nap", "ah", "aha"]
26   - if Searchkick.server_below?("8.0.0")
  26 + if prefix_length_misspellings_off?
27 27 assert_search "ap ah", ["ap", "ah"], operator: "or", misspellings: {prefix_length: 2}
28 28 else
29 29 assert_search "ap ah", ["ap", "ah", "api", "apt", "aha"], operator: "or", misspellings: {prefix_length: 2}
... ... @@ -110,4 +110,10 @@ class MisspellingsTest &lt; Minitest::Test
110 110 store_names ["Sriracha"]
111 111 assert_search "siracha", ["Sriracha"], fields: [{name: :word_middle}], misspellings: {fields: [:name]}
112 112 end
  113 +
  114 + private
  115 +
  116 + def prefix_length_misspellings_off?
  117 + Searchkick.opensearch? ? Searchkick.server_below?("2.0.0", true) : Searchkick.server_below?("8.0.0")
  118 + end
113 119 end
... ...