mrkamel / search_cop

Search engine like fulltext query support for ActiveRecord
MIT License
825 stars 39 forks source link

Attribute (case insensitive / ILIKE) #50

Closed anaice closed 5 years ago

anaice commented 5 years ago

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
mrkamel commented 5 years ago

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:

anaice commented 5 years ago

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.

mrkamel commented 5 years ago

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