Attribute (case insensitive / ILIKE)
Closed this issue · 3 comments
Hello,
Thanks for this excellent gem!
I have a doubt: is it possible to add an ignore case option for attribute?
class Book < ActiveRecord::Base
# ...
search_scope :search do
attributes :title, :author
# uses ILIKE when :ignore_case
options :title, :ignore_case => true
options :author, :ignore_case => true
end
# ...
end
ILIKE
is afaik not in a sql standard, but a postgres extension. mysql and sqlite don't have it - and you need to use collations there or modifiers like UPPER
or LOWER
.
However, if you only seek for being case insensitive:
- when you are on postgres, search_cop will use
ILIKE
out of the box. - If you are on mysql, and use e.g. utf8_general_ci, it should ignore case as well out of the box.
I understand. It is not ANSI SQL, so when using postgres ILIKE is used.
I believe my problem is that my application uses the Postgis adapter (https://github.com/rgeo/activerecord-postgis-adapter)
After seeing your answer I evaluated the file:
search_cop / lib / search_cop / visitors / visitor.rb
I believe this part is not running and postgres specific commands are not used:
#...
extend (SearchCop :: Visitors :: Postgres) if @ connection.adapter_name = ~ / postgres / i
#...
I also did a quick check on the app:
irb(main):004:0> ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
=> false
irb(main):005:0> ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::PostGISAdapter
=> true
irb(main):006:0> ActiveRecord::Base.connection.adapter_name
=> "PostGIS"
Is there any way to manually set the pg extension in the gem?
Thank's for your time.
PS: Old programmer, but new rubyist here. Sorry for any nonsense.
i see, thx for detailed info. i'll then make the postgis adapter use the postgres extensions. if you feel like it, create a PR. greetings