lib/searchkick/index.rb in searchkick-0.9.1 vs lib/searchkick/index.rb in searchkick-1.0.0
- old
+ new
@@ -98,11 +98,11 @@
end
end
def similar_record(record, options = {})
like_text = retrieve(record).to_hash
- .keep_if { |k, v| !options[:fields] || options[:fields].map(&:to_s).include?(k) }
+ .keep_if { |k, _| !options[:fields] || options[:fields].map(&:to_s).include?(k) }
.values.compact.join(" ")
# TODO deep merge method
options[:where] ||= {}
options[:where][:_id] ||= {}
@@ -116,13 +116,11 @@
# search
def search_model(searchkick_klass, term = nil, options = {}, &block)
query = Searchkick::Query.new(searchkick_klass, term, options)
- if block
- block.call(query.body)
- end
+ block.call(query.body) if block
if options[:execute] == false
query
else
query.execute
end
@@ -347,10 +345,13 @@
settings.deep_merge!(options[:settings] || {})
# synonyms
synonyms = options[:synonyms] || []
+
+ synonyms = synonyms.call if synonyms.respond_to?(:call)
+
if synonyms.any?
settings[:analysis][:filter][:searchkick_synonym] = {
type: "synonym",
synonyms: synonyms.select { |s| s.size > 1 }.map { |s| s.join(",") }
}
@@ -377,20 +378,20 @@
settings[:analysis][:analyzer][:default_index][:filter].insert(4, "searchkick_wordnet")
settings[:analysis][:analyzer][:default_index][:filter] << "searchkick_wordnet"
end
if options[:special_characters] == false
- settings[:analysis][:analyzer].each do |analyzer, analyzer_settings|
+ settings[:analysis][:analyzer].each do |_, analyzer_settings|
analyzer_settings[:filter].reject! { |f| f == "asciifolding" }
end
end
mapping = {}
# conversions
- if options[:conversions]
- mapping[:conversions] = {
+ if (conversions_field = options[:conversions])
+ mapping[conversions_field] = {
type: "nested",
properties: {
query: {type: "string", analyzer: "searchkick_keyword"},
count: {type: "integer"}
}
@@ -559,8 +560,7 @@
end
else
obj
end
end
-
end
end