lib/searchkick/index.rb in searchkick-1.1.2 vs lib/searchkick/index.rb in searchkick-1.2.0
- old
+ new
@@ -100,11 +100,11 @@
# TODO deep merge method
options[:where] ||= {}
options[:where][:_id] ||= {}
options[:where][:_id][:not] = record.id.to_s
- options[:limit] ||= 10
+ options[:per_page] ||= 10
options[:similar] = true
# TODO use index class instead of record class
search_model(record.class, like_text, options)
end
@@ -130,11 +130,16 @@
index
end
# remove old indices that start w/ index_name
def clean_indices
- all_indices = client.indices.get_aliases
+ all_indices =
+ begin
+ client.indices.get_aliases
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
+ []
+ end
indices = all_indices.select { |k, v| (v.empty? || v["aliases"].empty?) && k =~ /\A#{Regexp.escape(name)}_\d{14,17}\z/ }.keys
indices.each do |index|
Searchkick::Index.new(index).delete
end
indices
@@ -406,33 +411,35 @@
}
}
end
mapping_options = Hash[
- [:autocomplete, :suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight, :searchable]
+ [:autocomplete, :suggest, :word, :text_start, :text_middle, :text_end, :word_start, :word_middle, :word_end, :highlight, :searchable, :only_analyzed]
.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|
field_mapping = {
type: "multi_field",
- fields: {
- field => {type: "string", index: "not_analyzed"}
- }
+ fields: {}
}
+ unless mapping_options[:only_analyzed].include?(field)
+ field_mapping[:fields][field] = {type: "string", index: "not_analyzed"}
+ end
+
if !options[:searchable] || mapping_options[:searchable].include?(field)
if word
field_mapping[:fields]["analyzed"] = {type: "string", index: "analyzed"}
if mapping_options[:highlight].include?(field)
field_mapping[:fields]["analyzed"][:term_vector] = "with_positions_offsets"
end
end
- mapping_options.except(:highlight, :searchable).each do |type, fields|
+ mapping_options.except(:highlight, :searchable, :only_analyzed).each do |type, fields|
if options[:match] == type || fields.include?(field)
field_mapping[:fields][type] = {type: "string", index: "analyzed", analyzer: "searchkick_#{type}_index"}
end
end
end