'MongoDb $text search returning unexpected partial match

I have a collection in Mongodb (ServerVersion 4.4.4) with several fields, of these fields I am interested in the following three of them:

  1. denominazionePunto;
  2. indirizzo;
  3. citta.

From these three fields I have created additional (corresponding) array fields (indirizzoWords, denominazionePuntoWords and cittaWords) for startsWith searches as suggested in:

Efficient partial keyword searches

I did this because I know text index only support exact matching, so I created all the possible prefix string in the *Words arrays. E.g.: "citta"="Venice" => "cittaWords"=["venice", "venic", "veni", "ven"] (Searches are composed of at least three characters).

Additionally I needed to search on these fields with weights, so I created the following text index on my mongoDb database:

db.collection.createIndex(
    {
        indirizzoWords: "text",
        denominazionePuntoWords: "text",
        cittaWords: "text"
    },
    {
        weights: {
            denominazionePuntoWords: 10,
            cittaWords: 5,
            indirizzoWords: 2
        },
        name: "TextIndex",
        default_language: "none" 
    }
)

Following the advice on this answer to search for all the terms in a phrase:

MongoDB Text Search AND multiple search words

I performed the following find:

db.collection.find({
    "$text": { "$search": "\"via\" \"Roma\" \"essic\"" }
})
.sort({ score: { $meta: 'textScore' } })
.projection({ denominazionePunto: 1, indirizzo: 1, citta: 1, score: { $meta: "textScore" } });

I expected all the three string to be found as an exact match setting default_language=none, what I get is:

Partial Match for string "essic" but not as a prefix

How is it possible that the string essic is being found in Gessica and Jessica? It looks like it is a partial matching. Why searching for "$text": { "$search": "\"essic\"" } gives me no result at all? Non deterministic behaviours drive me crazy.

The denominazionePuntoWords for Gessica case is:

"denominazionePuntoWords" : [
    "gessica",
    "guerra",
    "ges",
    "gess",
    "gessi",
    "gessic",
    "gue",
    "guer",
    "guerr"
]

As you can see there are only prefixes and essic is no where to be found if not partially.

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source