Commit 1a0ff891d3a1367b1760df6e3389a7fbbaf4e720

Authored by Andrew Kane
1 parent 88349791

Added max_expansions option to misspellings

Showing 1 changed file with 2 additions and 1 deletions   Show diff stats
lib/searchkick/query.rb
@@ -111,6 +111,7 @@ module Searchkick @@ -111,6 +111,7 @@ module Searchkick
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 = (misspellings.is_a?(Hash) && misspellings[:transpositions] == true) ? {fuzzy_transpositions: true} : {}
113 prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0 113 prefix_length = (misspellings.is_a?(Hash) && misspellings[:prefix_length]) || 0
  114 + max_expansions = (misspellings.is_a?(Hash) && misspellings[:max_expansions]) || 3
114 end 115 end
115 116
116 if field == "_all" || field.end_with?(".analyzed") 117 if field == "_all" || field.end_with?(".analyzed")
@@ -128,7 +129,7 @@ module Searchkick @@ -128,7 +129,7 @@ module Searchkick
128 end 129 end
129 130
130 if misspellings != false 131 if misspellings != false
131 - qs.concat qs.map { |q| q.except(:cutoff_frequency).merge(fuzziness: edit_distance, prefix_length: prefix_length, max_expansions: 3, boost: factor).merge(transpositions) } 132 + qs.concat qs.map { |q| q.except(:cutoff_frequency).merge(fuzziness: edit_distance, prefix_length: prefix_length, max_expansions: max_expansions, boost: factor).merge(transpositions) }
132 end 133 end
133 134
134 queries.concat(qs.map { |q| {match: {field => q}} }) 135 queries.concat(qs.map { |q| {match: {field => q}} })