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 6665547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:44:05+00:00 2026-05-26T02:44:05+00:00

I have a little problem with search functionality on my RoR based site. I

  • 0

I have a little problem with search functionality on my RoR based site. I have many Produts with some CODEs. This code can be any string like "AB-123-lHdfj". Now I use ILIKE operator to find products:

Product.where("code ILIKE ?", "%" + params[:search] + "%")

It works fine, but it can’t find product with codes like "AB123-lHdfj", or "AB123lHdfj".

What should I do for this? May be Postgres has some string normalization function, or some other methods to help me?

  • 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-26T02:44:06+00:00Added an answer on May 26, 2026 at 2:44 am

    Postgres provides a module with several string comparsion functions such as soundex and metaphone. But you will want to use the levenshtein edit distance function.

    Example:
    
    test=# SELECT levenshtein('GUMBO', 'GAMBOL');
     levenshtein
    -------------
               2
    (1 row)
    

    The 2 is the edit distance between the two words. When you apply this against a number of words and sort by the edit distance result you will have the type of fuzzy matches that you’re looking for.

    Try this query sample: (with your own object names and data of course)

    SELECT * 
    FROM some_table
    WHERE levenshtein(code, 'AB123-lHdfj') <= 3
    ORDER BY levenshtein(code, 'AB123-lHdfj')
    LIMIT 10
    

    This query says:

    Give me the top 10 results of all data from some_table where the edit distance between the code value and the input ‘AB123-lHdfj’ is less than 3. You will get back all rows where the value of code is within 3 characters difference to ‘AB123-lHdfj’…

    Note: if you get an error like:

    function levenshtein(character varying, unknown) does not exist
    

    Install the fuzzystrmatch extension using:

    test=# CREATE EXTENSION fuzzystrmatch;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with my if(isset($_POST['submit'])) code. What I want is some
I have a little problem with a Listview. I can load it with listview
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have this little problem, that I cannot figure out which arguments to pass
I have a little problem. I had some JComboBox to a JDialog but they
I have a little, but nasty problem: I have a database with many records,
I know how to approach this problem but i have very little experience dealing
I have scoured the web in search of a solution to this problem, but
I have a little problem. I have some dynamically created tables and each row
I have a little problem with my Solr search engine. It does not return

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.