Postgres accent insensitive LIKE search in Rails 3.1 on Heroku

后端 未结 5 2252
无人及你
无人及你 2021-02-05 11:11

How can I modify a where/like condition on a search query in Rails:

find(:all, :conditions => [\"lower(name) LIKE ?\", \"%#{search.downcase}%\"])

5条回答
  •  半阙折子戏
    2021-02-05 11:50

    For those like me who are having trouble on add the unaccent extension for PostgreSQL and get it working with the Rails application, here is the migration you need to create:

    class AddUnaccentExtension < ActiveRecord::Migration
      def up
        execute "create extension unaccent"
      end
    
      def down
        execute "drop extension unaccent"
      end
    end
    

    And, of course, after rake db:migrate you will be able to use the unaccent function in your queries: unaccent(column) similar to ... or unaccent(lower(column)) ...

提交回复
热议问题