Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:00:25+00:00 2026-05-29T19:00:25+00:00

How can I modify a where/like condition on a search query in Rails: find(:all,

  • 0

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

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

so that the results are matched irrespective of accents? (eg métro = metro). Because I’m using utf8, I can’t use “to_ascii”. Production is running on Heroku.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:00:26+00:00Added an answer on May 29, 2026 at 7:00 pm

    Proper solution

    Since PostgreSQL 9.1 you can just:

    CREATE EXTENSION unaccent;
    

    Provides a function unaccent(), doing what you need (except for lower(), just use that additionally if needed). Read the manual about this extension.

    More about unaccent and indexes:

    • Does PostgreSQL support "accent insensitive" collations?

    Poor man’s solution

    If you can’t install unacccent, but are able to create a function. I compiled the list starting here and added to it over time. It is comprehensive, but hardly complete:

    CREATE OR REPLACE FUNCTION lower_unaccent(text)
      RETURNS text
      LANGUAGE sql IMMUTABLE STRICT AS
    $func$
    SELECT lower(translate($1
         , '¹²³áàâãäåāăąÀÁÂÃÄÅĀĂĄÆćčç©ĆČÇĐÐèéêёëēĕėęěÈÊËЁĒĔĖĘĚ€ğĞıìíîïìĩīĭÌÍÎÏЇÌĨĪĬłŁńňñŃŇÑòóôõöōŏőøÒÓÔÕÖŌŎŐØŒř®ŘšşșߊŞȘùúûüũūŭůÙÚÛÜŨŪŬŮýÿÝŸžżźŽŻŹ'
         , '123aaaaaaaaaaaaaaaaaaacccccccddeeeeeeeeeeeeeeeeeeeeggiiiiiiiiiiiiiiiiiillnnnnnnooooooooooooooooooorrrsssssssuuuuuuuuuuuuuuuuyyyyzzzzzz'
         ));
    $func$;
    

    Your query should work like that:

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

    For left-anchored searches, you can use an index on the function for very fast results:

    CREATE INDEX tbl_name_lower_unaccent_idx
      ON fest (lower_unaccent(name) text_pattern_ops);
    

    For queries like:

    SELECT * FROM tbl WHERE (lower_unaccent(name)) LIKE 'bob%';
    

    Or use COLLATE "C". See:

    • PostgreSQL LIKE query performance variations
    • Is there a difference between text_pattern_ops and COLLATE "C"?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can modify some style to all elements that matches
In android the Toggle buttons are looks like below - Can we modify this
Can anybody confirm or deny that I can modify default styles provided by StyleCop
Some C functions can modify the string value without that I pass the address
I'm trying to understand code that I bought so I can modify it. In
I have some MySQL results like this: --------------------------- | name | something_random | ---------------------------
Hello question on like condition using lambda expression. I hope you can reply to
I am writing a JPA QL named query that would search for documents. This
I'm trying to integrate with some software (that I can't modify) that queries a
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.