lib/mongoid_search/util.rb in mongoid_search-0.3.4 vs lib/mongoid_search/util.rb in mongoid_search-0.3.5
- old
+ new
@@ -1,30 +1,30 @@
-# encoding: utf-8
+
module Mongoid::Search::Util
def self.keywords(klass, fields)
if fields.is_a?(Array)
fields.map do |field|
- self.keywords(klass, field)
+ keywords(klass, field)
end
elsif fields.is_a?(Hash)
fields.keys.map do |field|
attribute = klass.send(field)
unless attribute.blank?
if attribute.is_a?(Array)
- attribute.map{ |a| self.keywords(a, fields[field]) }
+ attribute.map { |a| keywords(a, fields[field]) }
else
- self.keywords(attribute, fields[field])
+ keywords(attribute, fields[field])
end
end
end
else
- value = if klass.respond_to?(fields.to_s + "_translations")
- klass.send(fields.to_s + "_translations").values
+ value = if klass.respond_to?(fields.to_s + '_translations')
+ klass.send(fields.to_s + '_translations').values
elsif klass.respond_to?(fields)
klass.send(fields)
else
- value = klass[fields];
+ value = klass[fields]
end
value = value.join(' ') if value.respond_to?(:join)
normalize_keywords(value) if value
end
end
@@ -36,21 +36,20 @@
stem_proc = Mongoid::Search.stem_proc
strip_symbols = Mongoid::Search.strip_symbols
strip_accents = Mongoid::Search.strip_accents
return [] if text.blank?
- text = text.to_s.
- mb_chars.
- normalize(:kd).
- downcase.
- to_s.
- gsub(strip_symbols, ' '). # strip symbols
- gsub(strip_accents, ''). # strip accents
- gsub(/[#{ligatures.keys.join("")}]/) {|c| ligatures[c]}.
- split(' ').
- reject { |word| word.size < Mongoid::Search.minimum_word_size }
+ text = text.to_s
+ .mb_chars
+ .normalize(:kd)
+ .downcase
+ .to_s
+ .gsub(strip_symbols, ' ') # strip symbols
+ .gsub(strip_accents, '') # strip accents
+ .gsub(/[#{ligatures.keys.join("")}]/) { |c| ligatures[c] }
+ .split(' ')
+ .reject { |word| word.size < Mongoid::Search.minimum_word_size }
text = text.reject { |word| ignore_list.include?(word) } unless ignore_list.blank?
text = text.map(&stem_proc) if stem_keywords
text
end
-
end