How to implement 'did you mean' feature in Bagisto?

Hi,

I’m exploring ways to add a “Did You Mean” functionality to Bagisto’s product search. I want to handle typos and provide suggestions for users.

Has anyone implemented this before? Is Elasticsearch necessary, or are there alternative approaches? Any guidance, examples, or best practices would be greatly appreciated.

Hi,

If you want to implement a “Did You Mean” feature in Bagisto to handle typos and suggest correct products, there are a couple of approaches you can take.

  1. Using Elasticsearch (Recommended for large catalogs):

    • Bagisto supports Elasticsearch integration.

    • It provides fuzzy search and suggesters that can automatically suggest correct terms.

    • Example query:

GET /products/_search
{
  "suggest": {
    "text": "iphon",
    "term": { "field": "name" }
  }
}

  1. Alternative Approaches (Without Elasticsearch):
  • Use Levenshtein distance to compare user input with product names.

  • PHP functions like similar_text() or libraries like fuzzy-string-match can suggest close matches.

  • Maintain a dictionary of common typos mapped to correct products.

Thank you, @chandrasekhar121. This explanation can be very helpful. I’ll proceed with implementing the Elasticsearch suggester approach for our catalog.