#619 open
tomP

[Enhance Req] Add support for case insensitive search when using postgresql

Reported by tomP | February 2nd, 2010 @ 01:54 PM | in Hobo 1.1

Not tested, just a suggestion.

in find_by_search:

      search_targets.build_hash do |search_target|
        conditions = []
        parameters = []
+       like_operator = 'like'
+       if ActiveRecord::Base.connection.instance_variable_get ("@config")[:adapter] == 'postgresql'
+           like_operator = 'ilike'
+       end
        query_words.each do |word|
-         column_queries = search_target.search_columns.map { |column| "#{column} like ?" }
+         column_queries = search_target.search_columns.map { |column| "#{column} #{like_operator} ?" }
          conditions << "(" + column_queries.join(" or ") + ")"
          parameters.concat(["%#{word}%"] * column_queries.length)
        end
        conditions = conditions.join(" and ")

        results = search_target.find(:all, :conditions => [conditions, *parameters])
        [search_target.name, results] unless results.empty?
      end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Referenced by

Pages