Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining which words were matched in a fuzzy search

I'm running a fuzzy search, and need to see which words were matched. For example, if I am searching for the query testing, and it matches a field with the sentence The boy was resting, I need to be able to know that the match was due to the word resting.

I tried setting the parameter explain = true, but it doesn't seem to contain the information I need. Any thoughts?

like image 943
Ari Avatar asked Feb 13 '14 20:02

Ari


People also ask

What is fuzzy in matching rule?

For the fuzzy matching method, various fuzzy matching algorithms can be used. Each matching algorithm is scored based on how closely it matches the two fields. For example, if you select exact matching and the two fields match, the match score is 100. If the two fields don't match, the score is 0.

What is fuzzy name matching?

What is fuzzy name matching? Fuzzy matching assigns a probability to a match between 0.0 and 1.0 based on linguistic and statistical methods instead of just choosing either 1 (true) or 0 (false). As a result, names Robert and Bob can be a match with high probability even though they're not identical.

What is fuzzy matching example?

Fuzzy Matching (also called Approximate String Matching) is a technique that helps identify two elements of text, strings, or entries that are approximately similar but are not exactly the same. For example, let's take the case of hotels listing in New York as shown by Expedia and Priceline in the graphic below.


1 Answers

Alright, this is what I was looking for:

After a bit of research, I found the Highlighting feature of elasticsearch.

By default it returns a snippet of context surrounding the match, but you can set the fragment size to the query length to return only the exact match. For example:

{
    query : query,
    highlight : {
        "fields" : {
            'text' : {
                "fragment_size" : query.length
            }
        }
    }
}
like image 153
Ari Avatar answered Sep 24 '22 14:09

Ari