lib/searchkick/index_options.rb in searchkick-1.5.1 vs lib/searchkick/index_options.rb in searchkick-2.0.0

- old
+ new

@@ -10,11 +10,11 @@ mappings = options[:mappings] else below22 = Searchkick.server_below?("2.2.0") below50 = Searchkick.server_below?("5.0.0-alpha1") default_type = below50 ? "string" : "text" - default_analyzer = below50 ? :default_index : :default + default_analyzer = :searchkick_index keyword_mapping = if below50 { type: default_type, index: "not_analyzed" @@ -56,15 +56,10 @@ char_filter: ["ampersand"], tokenizer: "standard", filter: ["standard", "lowercase", "asciifolding", "searchkick_stemmer"] }, # https://github.com/leschenko/elasticsearch_autocomplete/blob/master/lib/elasticsearch_autocomplete/analyzers.rb - searchkick_autocomplete_index: { - type: "custom", - tokenizer: "searchkick_autocomplete_ngram", - filter: ["lowercase", "asciifolding"] - }, searchkick_autocomplete_search: { type: "custom", tokenizer: "keyword", filter: ["lowercase", "asciifolding"] }, @@ -147,17 +142,10 @@ # &_to_and ampersand: { type: "mapping", mappings: ["&=> and "] } - }, - tokenizer: { - searchkick_autocomplete_ngram: { - type: "edgeNGram", - min_gram: 1, - max_gram: 50 - } } } } if Searchkick.env == "test" @@ -231,20 +219,20 @@ } } end mapping_options = Hash[ - [:autocomplete, :suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight, :searchable, :filterable, :only_analyzed] + [:suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight, :searchable, :filterable] .map { |type| [type, (options[type] || []).map(&:to_s)] } ] word = options[:word] != false && (!options[:match] || options[:match] == :word) mapping_options.values.flatten.uniq.each do |field| fields = {} - if mapping_options[:only_analyzed].include?(field) || (options.key?(:filterable) && !mapping_options[:filterable].include?(field)) + if options.key?(:filterable) && !mapping_options[:filterable].include?(field) fields[field] = {type: default_type, index: "no"} else fields[field] = keyword_mapping end @@ -255,11 +243,11 @@ if mapping_options[:highlight].include?(field) fields["analyzed"][:term_vector] = "with_positions_offsets" end end - mapping_options.except(:highlight, :searchable, :filterable, :only_analyzed, :word).each do |type, f| + mapping_options.except(:highlight, :searchable, :filterable, :word).each do |type, f| if options[:match] == type || f.include?(field) fields[type] = {type: default_type, index: "analyzed", analyzer: "searchkick_#{type}_index"} end end end @@ -284,17 +272,10 @@ options[:geo_shape] = options[:geo_shape].product([{}]).to_h if options[:geo_shape].is_a?(Array) (options[:geo_shape] || {}).each do |field, shape_options| mapping[field] = shape_options.merge(type: "geo_shape") end - (options[:unsearchable] || []).map(&:to_s).each do |field| - mapping[field] = { - type: default_type, - index: "no" - } - end - routing = {} if options[:routing] routing = {required: true} unless options[:routing] == true routing[:path] = options[:routing].to_s @@ -334,11 +315,10 @@ } else dynamic_fields["{name}"].merge(fields: dynamic_fields.except("{name}")) end - # TODO make dynamic - all_enabled = true + all_enabled = !options[:searchable] || options[:searchable].to_a.include?("_all") mappings = { _default_: { _all: all_enabled ? {type: default_type, index: "analyzed", analyzer: default_analyzer} : {enabled: false}, properties: mapping,