Class: Searchgasm::Condition::Keywords

Inherits:
Base
  • Object
show all
Defined in:
lib/searchgasm/condition/keywords.rb

Constant Summary collapse

BLACKLISTED_WORDS =

from ranks.nl

('a'..'z').to_a + ["about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "in", "is", "it", "la", "of", "on", "or", "that", "the", "the", "this", "to", "und", "was", "what", "when", "where", "who", "will", "with", "www"]
FOREIGN_CHARACTERS =
'àáâãäåßéèêëìíîïñòóôõöùúûüýÿ'

Instance Attribute Summary

Attributes inherited from Base

#column, #column_for_type_cast, #column_sql, #column_sql_format, #klass, #table_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

condition_names_for_model, condition_type_name, #explicitly_set_value=, #explicitly_set_value?, handle_array_value?, ignore_meaningless_value?, #initialize, join_arrays_with_or?, #options, #sanitize, #value, #value=, #value_is_meaningless?

Constructor Details

This class inherits a constructor from Searchgasm::Condition::Base

Class Method Details

.condition_names_for_columnObject



11
12
13
# File 'lib/searchgasm/condition/keywords.rb', line 11

def condition_names_for_column
  super + ["kwords", "kw"]
end

Instance Method Details

#to_conditions(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/searchgasm/condition/keywords.rb', line 16

def to_conditions(value)
  strs = []
  subs = []
  
  search_parts = value.gsub(/,/, " ").split(/ /)
  replace_non_alnum_characters!(search_parts)
  search_parts.uniq!
  remove_blacklisted_words!(search_parts)
  return if search_parts.blank?
  
  search_parts.each do |search_part|
    strs << "#{column_sql} #{like_condition_name} ?"
    subs << "%#{search_part}%"
  end
  
  [strs.join(" AND "), *subs]
end