From 5cf51a9f078bd04635f717a14fd627ead89a1a08 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sat, 5 Dec 2015 20:21:26 -0800 Subject: [PATCH] Added match option to searchkick method --- lib/searchkick/index.rb | 5 ++++- lib/searchkick/query.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index 6ad2b55..193da2e 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -464,10 +464,13 @@ module Searchkick "{name}" => {type: "string", index: "not_analyzed"} } - unless options[:word] == false + if options[:match] && options[:match] != :word + dynamic_fields[options[:match]] = {type: "string", index: "analyzed", analyzer: "searchkick_#{options[:match]}_index"} + elsif options[:word] != false dynamic_fields["analyzed"] = {type: "string", index: "analyzed"} end + mappings = { _default_: { properties: mapping, diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 2ad311f..c201100 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -30,7 +30,7 @@ module Searchkick options[:fields].map { |f| "#{f}.autocomplete" } else options[:fields].map do |value| - k, v = value.is_a?(Hash) ? value.to_a.first : [value, options[:match] || :word] + k, v = value.is_a?(Hash) ? value.to_a.first : [value, options[:match] || searchkick_options[:match] || :word] k2, boost = k.to_s.split("^", 2) field = "#{k2}.#{v == :word ? 'analyzed' : v}" boost_fields[field] = boost.to_f if boost -- libgit2 0.21.0