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, #klass, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

aliases_for_klass, comparable_column?, condition_name, #condition_name, #explicitly_set_value=, #explicitly_set_value?, #ignore_blanks?, #initialize, #name, name_for_klass, #quote_column_name, #quote_table_name, #quoted_column_name, #quoted_table_name, #sanitize, string_column?

Constructor Details

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

Class Method Details

.aliases_for_column(column) ⇒ Object



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

def aliases_for_column(column)
  ["#{column.name}_kwords", "#{column.name}_kw"]
end

.name_for_column(column) ⇒ Object



7
8
9
10
# File 'lib/searchgasm/condition/keywords.rb', line 7

def name_for_column(column)
  return unless string_column?(column)
  super
end

Instance Method Details

#to_conditions(value) ⇒ Object



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

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 << "#{quoted_table_name}.#{quoted_column_name} LIKE ?"
    subs << "%#{search_part}%"
  end
  
  [strs.join(" AND "), *subs]
end