Permalink
Browse files

'ILIKE' keyword is used instead of 'LIKE' when generating sql for con…

…ditions for PostgreSQL adapter

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
  • Loading branch information...
1 parent 7c7b32a commit bc41b842fc3de4c0e24b40a5d3ac795e1f09db20 kazjote committed with Jul 28, 2009
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/searchlogic/named_scopes/conditions.rb
@@ -140,6 +140,8 @@ def primary_condition_details(name)
def create_primary_condition(column, condition)
column_type = columns_hash[column.to_s].type
+ match_keyword =
+ ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
scope_options = case condition.to_s
when /^equals/
scope_options(condition, column_type, "#{table_name}.#{column} = ?")
@@ -154,17 +156,17 @@ def create_primary_condition(column, condition)
when /^greater_than/
scope_options(condition, column_type, "#{table_name}.#{column} > ?")
when /^like/
- scope_options(condition, column_type, "#{table_name}.#{column} LIKE ?", :like)
+ scope_options(condition, column_type, "#{table_name}.#{column} #{match_keyword} ?", :like)
when /^not_like/
- scope_options(condition, column_type, "#{table_name}.#{column} NOT LIKE ?", :like)
+ scope_options(condition, column_type, "#{table_name}.#{column} NOT #{match_keyword} ?", :like)
when /^begins_with/
- scope_options(condition, column_type, "#{table_name}.#{column} LIKE ?", :begins_with)
+ scope_options(condition, column_type, "#{table_name}.#{column} #{match_keyword} ?", :begins_with)
when /^not_begin_with/
- scope_options(condition, column_type, "#{table_name}.#{column} NOT LIKE ?", :begins_with)
+ scope_options(condition, column_type, "#{table_name}.#{column} NOT #{match_keyword} ?", :begins_with)
when /^ends_with/
- scope_options(condition, column_type, "#{table_name}.#{column} LIKE ?", :ends_with)
+ scope_options(condition, column_type, "#{table_name}.#{column} #{match_keyword} ?", :ends_with)
when /^not_end_with/
- scope_options(condition, column_type, "#{table_name}.#{column} NOT LIKE ?", :ends_with)
+ scope_options(condition, column_type, "#{table_name}.#{column} NOT #{match_keyword} ?", :ends_with)
when "null"
{:conditions => "#{table_name}.#{column} IS NULL"}
when "not_null"

0 comments on commit bc41b84

Please sign in to comment.