Autocomplete search

Hi,

I’m trying to implement a search feature in my NodeJS project.
The field I want to search:

full_name: {
      type: String,
      text: true,
 },

I want the search to return results where the search term make up only a part of the value. Is autocomplete the only way to achieve this?
For example: “Hen” or “sing” should return “Henry Kissinger”.

I also want to return results within 1-2 typos and I want the results to be scored.
For example: “Hen” should return “Henry Johnson” and “Herman Johnson” but with a better score for the former.

Going with this tutorial/workaround:

I have created a search index like this:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "full_name": [
        {
          "type": "string"
        },
        {
          "type": "autocomplete"
        }
      ]
    }
  }
}

And I query like this:

const users = await User.aggregate([

      {

        $search: {

          index: 'fullName',

          compound: {

            should: [

              {

                autocomplete: {

                  path: 'full_name',

                  query: term,

                  score: { boost: { value: 3 } },

                },

              },

              {

                text: {

                  path: 'last_name',

                  query: term,

                  fuzzy: { maxEdits: 1 },

                },

              },

            ],

          },

        },

      },

      {

        $project: {

          full_name: 1,

          score: { $meta: 'searchScore' },

        },

      },

    ]);

It seems like I have to choose between scoring and maxEdits. Applying maxEdits to the text part has no effect. Applying it to autocomplete causes the scores to be the same across the board.

Is there a solution to this?

Hi there, we have a tutorial for a handful of ways to do partial matching, check it out here. Will need to think more about your question regarding maxEdits vs. scoring…