Sha256: 53c3d047b759c3ec6f6957729fcba88e564c98eb5c520bce869eb509af4e4ff7

Contents?: true

Size: 523 Bytes

Versions: 1

Compression:

Stored size: 523 Bytes

Contents

module Util
      
  def self.keywords(text, stem_keywords, ignore_list)
    return [] if text.blank?
    text = text.
      mb_chars.
      normalize(:kd).
      to_s.
      gsub(/[._:;'"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/, ' '). # strip punctuation
      gsub(/[^[:alpha:]\s]/,'').  # strip accents
      downcase.
      split(' ').
      reject { |word| word.size < 2 }
    text = text.reject { |word| ignore_list.include?(word) } unless ignore_list.blank?
    text = text.map(&:stem) if stem_keywords
    text
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid_search-0.2.0 lib/mongoid_search/util.rb