Commit 892e5f39a60796889bfbcd6bfb3a46726610c93b

Authored by Andrew Kane
2 parents 91244626 56341623

Merge branch 'picocandy-misspellings_false_with_fields_operator'

Showing 2 changed files with 27 additions and 5 deletions   Show diff stats
lib/searchkick/query.rb
@@ -96,11 +96,6 @@ module Searchkick @@ -96,11 +96,6 @@ module Searchkick
96 } 96 }
97 97
98 if field == "_all" || field.end_with?(".analyzed") 98 if field == "_all" || field.end_with?(".analyzed")
99 - shared_options[:cutoff_frequency] = 0.001 unless operator == "and"  
100 - qs.concat [  
101 - shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search"),  
102 - shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search2")  
103 - ]  
104 misspellings = options.key?(:misspellings) ? options[:misspellings] : options[:mispellings] # why not? 99 misspellings = options.key?(:misspellings) ? options[:misspellings] : options[:mispellings] # why not?
105 if misspellings != false 100 if misspellings != false
106 edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1 101 edit_distance = (misspellings.is_a?(Hash) && (misspellings[:edit_distance] || misspellings[:distance])) || 1
@@ -110,6 +105,11 @@ module Searchkick @@ -110,6 +105,11 @@ module Searchkick
110 shared_options.merge(fuzziness: edit_distance, max_expansions: 3, analyzer: "searchkick_search2").merge(transpositions) 105 shared_options.merge(fuzziness: edit_distance, max_expansions: 3, analyzer: "searchkick_search2").merge(transpositions)
111 ] 106 ]
112 end 107 end
  108 + shared_options[:cutoff_frequency] = 0.001 unless operator == "and" || misspellings == false
  109 + qs.concat [
  110 + shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search"),
  111 + shared_options.merge(boost: 10 * factor, analyzer: "searchkick_search2")
  112 + ]
113 elsif field.end_with?(".exact") 113 elsif field.end_with?(".exact")
114 f = field.split(".")[0..-2].join(".") 114 f = field.split(".")[0..-2].join(".")
115 queries << {match: {f => shared_options.merge(analyzer: "keyword")}} 115 queries << {match: {f => shared_options.merge(analyzer: "keyword")}}
test/sql_test.rb
@@ -244,6 +244,28 @@ class TestSql &lt; Minitest::Test @@ -244,6 +244,28 @@ class TestSql &lt; Minitest::Test
244 assert_search "aaaa", ["aabb"], misspellings: {distance: 2} 244 assert_search "aaaa", ["aabb"], misspellings: {distance: 2}
245 end 245 end
246 246
  247 + def test_misspellings_fields_operator
  248 + store [
  249 + {name: "red", color: "red"},
  250 + {name: "blue", color: "blue"},
  251 + {name: "cyan", color: "blue green"},
  252 + {name: "magenta", color: "red blue"},
  253 + {name: "green", color: "green"}
  254 + ]
  255 + assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"], misspellings: false
  256 + end
  257 +
  258 + def test_fields_operator
  259 + store [
  260 + {name: "red", color: "red"},
  261 + {name: "blue", color: "blue"},
  262 + {name: "cyan", color: "blue green"},
  263 + {name: "magenta", color: "red blue"},
  264 + {name: "green", color: "green"}
  265 + ]
  266 + assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"]
  267 + end
  268 +
247 def test_fields 269 def test_fields
248 store [ 270 store [
249 {name: "red", color: "light blue"}, 271 {name: "red", color: "light blue"},