[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
-
Bryan Larsen February 2nd, 2010 @ 05:16 PM
- Tag changed from case_sensitivity, find_by_search, postgersql, search to rapid enhancement, search
I'll merge your patch just after 1.0 goes out the door.
The best way to send patches is through a github pull request. But this way is fine. If you create the patch via "git format-patch" and then attach them you will be properly attributed in the git logs.
-
Matt Jones February 2nd, 2010 @ 08:52 PM
This could use some more logic to properly handle other DBs with case-sensitive LIKE operators. Maybe there's a flag on the adapter someplace?
-
Bryan Larsen February 2nd, 2010 @ 10:10 PM
just put your hobo repository in RAILS_ROOT/vendor/plugins/hobo and
remove the config.gem in environment.rb, and it should work. There's
more things that you may need to do in
http://cookbook.hobocentral.net/recipes/27-how-to-switch-from-the-gem -
Bryan Larsen February 19th, 2010 @ 04:42 PM
- State changed from new to open
- Tag changed from rapid enhancement, search to controller compatability enhancement, search
- Milestone set to Hobo 1.1
ILIKE
is a postgresql extension, so I'll leave as is. Other databases probably need a different hack. -
Bryan Larsen February 19th, 2010 @ 05:13 PM
- State changed from open to resolved
(from [df9df4b79c30976a1e55ad535a495cd4ca69e4ed]) [#619 state:resolved] support case insensitive search on postgresql. thanks tomP
http://github.com/tablatom/hobo/commit/df9df4b79c30976a1e55ad535a49... -
Bryan Larsen February 19th, 2010 @ 06:27 PM
- State changed from resolved to open
reopening bug just to reopen the milestone. Sometimes Lighthouse is really annoying.
-
Bryan Larsen February 19th, 2010 @ 06:29 PM
- State changed from open to resolved
-
Bryan Larsen May 28th, 2010 @ 05:44 PM
- Tag changed from controller compatability enhancement, search to controller, enhancement, search
- State changed from resolved to open
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.
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
Tags
Referenced by
- 619 [Enhance Req] Add support for case insensitive search when using postgresql (from [df9df4b79c30976a1e55ad535a495cd4ca69e4ed]) [#619 s...