World is now on Opti ID! Learn more

Using fuzzy search to match user entered queries

agl
agl
Vote:
 

Hello, im trying use the fuzzy search functionality to match results based on a user entered query

My data example is car objects with a title like: "tesla model 3 5yj3 2017 ev 261hk" or "citroën berlingo er ec 2018 1.5 bluehdi 100 102hk".

Given a search query like "tesla 3 2017" id like to return the 5 cars with the titles, that is the most similar to to the query. However im having trouble configuring the fuzzy search in the find client to return any results in this case. If the search query is fairly close to the full title is works fine, however id like to use the results as suggestions to the user in a search bar.

The search query looks like:

public async Task<List<CarObj>> CarSearch(string searchString, int amount)
{
//yeilds no results no matter what i change the minSimilarity to
    var fuzzyResult = await findClient
        .Search<CarObj>()
        .Filter(x => x.Title.MatchFuzzy(searchString,0.8)).GetResultAsync();

    var searchResult = fuzzyResult.Take(amount);

    return searchResult.ToList();
}

Where 0.8 in the minSimilarity. Ive tried adjusting the minSimilarity to both extremes however this yeilded no usable result. Am i missing something?
In the end the plan is to token match the search string before to reduce the search space using fuzzy search, however this requires that i have fuzzy search working :)

#338528
Edited, May 22, 2025 7:13
Vote:
 

Hi,

I had the issue like this when trying to use fuzzy search with Filter. I did workaround for it by using search query instead of Filter.

You can found my workaround here: https://world.optimizely.com/blogs/binh-nguyen/dates/2024/5/optimizely-search-and-navigation--part-1--search-tips/

#338688
May 25, 2025 6:36
Vote:
 

Hey 

Match Fuzzy is a termlevel query.
It is executed against the raw (not analyzed) value of the Title field. Your filter, therefore, tries to find one term that is almost equal to the whole string "tesla 3 2017". No document contains that exact term, so the query returns 0 hits. -- problem with MatchFuzzy

 

Alternative: use a free‑text search instead of a filter

var result = await findClient
    .Search<CarObj>()
    .For(search + "~")              // the trailing tilde enables fuzzy for every term
    .InField(x => x.Title)
    .WithAndAsDefaultOperator()     // every word must exist
    .Take(amount)
    .GetResultAsync();
#339407
Edited, Jun 13, 2025 15:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.