Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fuzzy search for group of word / multiple terms

I need to make fuzzy searches on group of words (and not only single terms).

My database table have many strings, containing 1 or more words, and I need to find the best fit for a searched group of words.

E.G:

I search "pommes de terre", it should give "pomme de terre", and with inferior score, "pomme", "terre", or any possible matching term.

For single terms, it works perfectly, and corrects typoes, and heavy mistakes. But if I search for many terms, single terms have better scores than exact matches, and group of words:

Search: "pomme de terre"

  • poire, score:2.3862941
  • pomme, score:2.2527628
  • pomme de terre, score:1.1263814 <- Not high enough

Question

Is there a solution which gives a better score the more terms matches ? (the more fuzzy terms matches, the more score is high)

SETTINGS

Search Query:

{query: 
    {fuzzy_like_this: 
        { like_text: 'pomme de terre'}
    }
}

Settings:

:analysis => {
    :analyzer => {
        :folding => {
            :tokenizer => "icu_tokenizer",
            :filter => [ "icu_folding"]
        }
    }
}

I'm a beginner, using elasticsearch-rails. I tried to use suggest queries, but they are not usable with rails gem.

I have to precise that this search is a big part of my project...

like image 820
ArTiSTiX Avatar asked Oct 09 '14 18:10

ArTiSTiX


Video Answer


2 Answers

I had the same issue, and came to the conclusion that fuzzy query is not what I needed. Fuzzy queries are term-level queries. I got much better results with a match query, which you can apply fuzziness on thanks to the fuzziness param.

like image 175
Thomas Martin Avatar answered Sep 30 '22 06:09

Thomas Martin


I faced the same issue. Here's how I fixed it using Java-8 and ES-1.7.

QueryBuilders.multiMatchQuery("pommes de terre","name")
.fuzziness(3)
.minimumShouldMatch("90%")
.type(Type.MOST_FIELDS);

Note: minimumShouldMatch is what does the trick here.

like image 38
faisal pathan Avatar answered Sep 30 '22 07:09

faisal pathan