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"]

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



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

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

Instance Method Details

#to_conditions(value) ⇒ Object



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

def to_conditions(value)
  strs = []
  subs = []
  
  search_parts = value.gsub(/,/, " ").split(/ /).collect { |word| word.downcase.gsub(/[^[:alnum:]]/, ''); }.uniq.select { |word| !BLACKLISTED_WORDS.include?(word.downcase) && !word.blank? }
  return if search_parts.blank?
  
  search_parts.each do |search_part|
    strs << "#{column_sql} LIKE ?"
    subs << "%#{search_part}%"
  end
  
  [strs.join(" AND "), *subs]
end