lib/searchkick/index_options.rb in searchkick-hooopo-2.3.3 vs lib/searchkick/index_options.rb in searchkick-hooopo-2.3.4
- old
+ new
@@ -9,10 +9,11 @@
settings = options[:settings] || {}
mappings = options[:mappings]
else
below22 = Searchkick.server_below?("2.2.0")
below50 = Searchkick.server_below?("5.0.0-alpha1")
+ below60 = Searchkick.server_below?("6.0.0-alpha1")
default_type = below50 ? "string" : "text"
default_analyzer = :searchkick_index
keyword_mapping =
if below50
{
@@ -23,10 +24,14 @@
{
type: "keyword"
}
end
+ all = options.key?(:_all) ? options[:_all] : below60
+ index_true_value = below50 ? "analyzed" : true
+ index_false_value = below50 ? "no" : false
+
keyword_mapping[:ignore_above] = (options[:ignore_above] || 30000) unless below22
settings = {
analysis: {
analyzer: {
@@ -176,11 +181,11 @@
# http://elasticsearch-users.115913.n3.nabble.com/synonym-multi-words-search-td4030811.html
# I find the following approach effective if you are doing multi-word synonyms (synonym phrases):
# - Only apply the synonym expansion at index time
# - Don't have the synonym filter applied search
# - Use directional synonyms where appropriate. You want to make sure that you're not injecting terms that are too general.
- settings[:analysis][:analyzer][default_analyzer][:filter].insert(4, "searchkick_synonym")
+ settings[:analysis][:analyzer][default_analyzer][:filter].insert(4, "searchkick_synonym") if below60
settings[:analysis][:analyzer][default_analyzer][:filter] << "searchkick_synonym"
%w(word_start word_middle word_end).each do |type|
settings[:analysis][:analyzer]["searchkick_#{type}_index".to_sym][:filter].insert(2, "searchkick_synonym")
end
@@ -227,17 +232,17 @@
word = options[:word] != false && (!options[:match] || options[:match] == :word)
mapping_options[:searchable].delete("_all")
- analyzed_field_options = {type: default_type, index: "analyzed", analyzer: Searchkick.default_analyzed_analyzer}
+ analyzed_field_options = {type: default_type, index: index_true_value, analyzer: Searchkick.default_analyzed_analyzer}
mapping_options.values.flatten.uniq.each do |field|
fields = {}
if options.key?(:filterable) && !mapping_options[:filterable].include?(field)
- fields[field] = {type: default_type, index: "no"}
+ fields[field] = {type: default_type, index: index_false_value}
else
fields[field] = keyword_mapping
end
if !options[:searchable] || mapping_options[:searchable].include?(field)
@@ -249,11 +254,11 @@
end
end
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"}
+ fields[type] = {type: default_type, index: index_true_value, analyzer: "searchkick_#{type}_index"}
end
end
end
mapping[field] = fields[field].merge(fields: fields.except(field))
@@ -281,35 +286,36 @@
dynamic_fields = {
# analyzed field must be the default field for include_in_all
# http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/
# however, we can include the not_analyzed field in _all
# and the _all index analyzer will take care of it
- "{name}" => keyword_mapping.merge(include_in_all: !options[:searchable])
+ "{name}" => keyword_mapping
}
+ if below60 && all
+ dynamic_fields["{name}"][:include_in_all] = !options[:searchable]
+ end
+
if options.key?(:filterable)
- dynamic_fields["{name}"] = {type: default_type, index: "no"}
+ dynamic_fields["{name}"] = {type: default_type, index: index_false_value}
end
unless options[:searchable]
if options[:match] && options[:match] != :word
- dynamic_fields[options[:match]] = {type: default_type, index: "analyzed", analyzer: "searchkick_#{options[:match]}_index"}
+ dynamic_fields[options[:match]] = {type: default_type, index: index_true_value, analyzer: "searchkick_#{options[:match]}_index"}
end
if word
dynamic_fields["analyzed"] = analyzed_field_options
end
end
# http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/
multi_field = dynamic_fields["{name}"].merge(fields: dynamic_fields.except("{name}"))
- all_enabled = !options[:searchable] || options[:searchable].to_a.map(&:to_s).include?("_all")
-
mappings = {
_default_: {
- _all: all_enabled ? analyzed_field_options : {enabled: false},
properties: mapping,
_routing: routing,
# https://gist.github.com/kimchy/2898285
dynamic_templates: [
{
@@ -319,10 +325,17 @@
mapping: multi_field
}
}
]
}
- }.deep_merge(options[:mappings] || {})
+ }
+
+ if below60
+ all_enabled = all && (!options[:searchable] || options[:searchable].to_a.map(&:to_s).include?("_all"))
+ mappings[:_default_][:_all] = all_enabled ? analyzed_field_options : {enabled: false}
+ end
+
+ mappings = mappings.deep_merge(options[:mappings] || {})
end
{
settings: settings,
mappings: mappings