Fuzzy search doesn't return the expected result

I am using the following text query:

         $search: {
          index: 'default',
          compound: {
            must: [
              {
                text: {
                  query: 'car',
                  path: [
                    'translations.he-IL.displayName',
                    'translations.en-US.displayName',
                    'translations.he-IL.synonyms',
                    'translations.en-US.synonyms',
                  ],
                  fuzzy: { maxEdits: 1, maxExpansions: 4 },
                },
              },
            ],
            mustNot: [
              {
                equals: {
                  value: true,
                  path: 'isDeleted',
                },
              },
            ],
          },
        },

When searchTerm is an input.
It returns the following documents:

{
    "_id" : ObjectId("64f852cfaf24690f71daadb5"),
    "operationalName" : "Agar  E-406",
    "translations" : {
        "en-US" : {
            "displayName" : "Agar - E-406",
            "description" : "(thickener) (gelling agent) "
        },
        "he-IL" : {
            "displayName" : "אגר - E-406",
            "description" : "(thickener) (gelling agent) "
        }
    }
}
{
    "_id" : ObjectId("64f852cfaf24690f71dab683"),
    "operationalName" : "Black ear fungus",
    "translations" : {
        "en-US" : {
            "displayName" : "Black ear fungus"
        },
        "he-IL" : {
            "displayName" : "פטריות אוזן שחורות",
            "synonyms" : "פטריות פונגוס שחורות"
        }
    }
}
{
    "_id" : ObjectId("64f852cfaf24690f71dab25f"),
    "operationalName" : "Nitrogen (packaging gas) - E941",
    "translations" : {
        "en-US" : {
            "displayName" : "Nitrogen (packaging gas) - E941",
            "description" : "propellant"
        },
        "he-IL" : {
            "displayName" : "חנקן - E941",
            "description" : "propellant"
        }
    }
}
{
    "_id" : ObjectId("64f852cfaf24690f71dab5df"),
    "operationalName" : "בר שוקולד טבעוני כשר לפסח",
    "translations" : {
        "en-US" : {
            "displayName" : "Vegan chocolate bar kosher for Passover"
        },
        "he-IL" : {
            "displayName" : "בר שוקולד טבעוני כשר לפסח"
        }
    }
}
{
    "_id" : ObjectId("64f852cfaf24690f71dab12f"),
    "operationalName" : "Invert Sugar",
    "translations" : {
        "en-US" : {
            "displayName" : "Invert Sugar",
            "synonyms" : "invert syrup, invert sugar, simple syrup, sugar syrup, sugar water, bar syrup, sucrose inversion",
            "description" : " a syrup mixture of the monosaccharides glucose and fructose, It is sweeter than table sugar,[2] and foods that contain invert sugar retain moisture better and crystallize less easily than do those that use table sugar instead"
        },
        "he-IL" : {
            "displayName" : "סוכר אינוורטי",
            "synonyms" : "סירופ סוכר",
            "description" : " a syrup mixture of the monosaccharides glucose and fructose, It is sweeter than table sugar,[2] and foods that contain invert sugar retain moisture better and crystallize less easily than do those that use table sugar instead"
        }
    }
}

I fail to understand why 'carrot ’ is not returned as well (it returns only if I write the full word)

fuzzy isn’t that fuzzy (was he?). “car” to “carrot” is quite a number of edits, by the text.fuzzy calculation.

One technique is to augment your query with some additional clauses that make “car” account for “carrot” as well, such as adding a wildcard clause (under compound.should) for car*.

1 Like

Haven’t thought of that one since … kindergarten! :grin: