Question

As a requirement when performing a fuzzy search we need to distinguish results that are matches without fuzziness versus results that are matches because of fuzziness.

For example if the index has:

  • red car
  • foxy cart
  • blue car

And the query is "purple OR car~" with fuzziness of 1 then all will be results but "foxy cart" will be labeled especially as a fuzzy result. I was wondering if there is any support for this or anybody has a suggestion on how to go about implementing this feature? One option I'm guessing is setting the fuzziness to 0 and re-execute the query and then mark the difference. I appreciate if anybody can provide any other better suggestions? Thank you in advance.

Was it helpful?

Solution

Running two separate queries is the approach that makes the most sense to me.

You could run two queries such that one gets only exact matches, and the other gets only fuzzy results, such as:

  • exact matches only: purple car
  • fuzzy matches only: purple car~ -car

Which should make the sets mutually exclusive, so you don't have to go to the trouble of matching up the results of one query with those of the other. It also loses the ability to readily interleave fuzzy and exact results based on score, though. So whichever approach serves your purposes.

Also, if you just need to boost your exact matches to the top, query with both a fuzzy term, and a heavy boosted exact term should do this nicely, something like:

purple car~ car^100

OTHER TIPS

.NEST example:

                .Query(q => q
                .Bool(b => b
                        .Should(
                            st => st.Match(m => m.Query(term).Field(f => f.FullName).Fuzziness(Fuzziness.EditDistance(1)).Boost(1.1).MinimumShouldMatch("100%")),
                            st => st.Match(m => m.Query(term).Field(f => f.FullName).Boost(10).MinimumShouldMatch("100%"))
                        )))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top