diff --git a/app/models/person.rb b/app/models/person.rb index 66b9994b5..b21d3ef21 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -45,13 +45,22 @@ class Person < ActiveRecord::Base scope :searchable, joins(:profile).where(:profiles => {:searchable => true}) def self.search_query_string(query) - where_clause = <<-SQL - profiles.first_name LIKE ? OR - profiles.last_name LIKE ? OR - people.diaspora_handle LIKE ? OR - profiles.first_name LIKE ? OR - profiles.last_name LIKE ? - SQL + if postgres? + where_clause = <<-SQL + profiles.first_name ILIKE ? OR + profiles.last_name ILIKE ? OR + people.diaspora_handle ILIKE ? + SQL + else + where_clause = <<-SQL + profiles.first_name LIKE ? OR + profiles.last_name LIKE ? OR + people.diaspora_handle LIKE ? OR + profiles.first_name LIKE ? OR + profiles.last_name LIKE ? + SQL + end + sql = "" tokens = [] @@ -62,7 +71,7 @@ class Person < ActiveRecord::Base sql << " OR " unless i == 0 sql << where_clause tokens.concat([token, token, token]) - tokens.concat([up_token, up_token]) + tokens.concat([up_token, up_token]) unless postgres? end [sql, tokens] end diff --git a/config/environment.rb b/config/environment.rb index ba7e062ed..471ec22f5 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -2,6 +2,11 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +# check what database you have +def postgres? + @using_postgres ||= defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) +end + # Load the rails application require File.expand_path('../application', __FILE__) Haml::Template.options[:format] = :html5 @@ -36,8 +41,3 @@ module Devise end end end - -# check what database you have -def postgres? - @using_postgres ||= defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) -end