fuzzy search in full text search

Viewed 2528

I'm using postgresql to Full Text Search and I am finding that users will not receive results if there are misspellings.I want to use fuzzy search and full text search together.For example I could not combine Trigram indexes and full text search.

What is the best way to handle misspelt words in Postgres full text search?

2 Answers

I'd suggest that you either use full-text search or trigram similarity matching, but don't try to mix them.

Based on the requirement, I would say that trigram similarity matching is the better fit.

If you don't get a result using the similarity operator %, you have two choices:

  1. Lower the similarity threshold pg_trgm.similarity_threshold.

  2. Query in a different way so that you get the best matches, however „distant” they are:

    SELECT * FROM product ORDER BY katadi <-> ' pen' LIMIT 10;
    

    I think that would be the better solution.

To use fuzzy search you need to ensure the extension is present.

CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;

Check the documentation, but you apply the search like;

SELECT levenshtein('GUMBO', 'GAMBOL');

You could put the result into a column to order by perhaps? You should also investigate "regexp_replace" to fix some of your known misspellings

Related