Atlas search - autocomplete grouping

It would be great if you can provide us another solution we are looking for in regards to AutoComplete.

AutoComplete Definition

{
  "analyzer": "lucene.english",
  "searchAnalyzer": "lucene.english",
  "mappings": {
    "dynamic": false,
    "fields": {
      "name": [
        {
          "analyzer": "lucene.english",
          "maxGrams": 8,
          "minGrams": 3,
          "type": "autocomplete"
        },
        {
          "type": "stringFacet"
        }
      ]
    }
  },
  "storedSource": {
    "include": [
      "name"
    ]
  }
}

We tried using facet as we want to display duplicate only once and want to get result as given in following snapshot. But facet seems to be grouping on whole name field in which case we will get every record as unique
Example : we want result as in following snapshot when “floor” is searched it shows only unique (“floor mat”, “floor lamp”) where name field data have “floor mat for dodge” , “floor mat for jeep” , “floor lamp for living room”, “floor lamp with table”…

image

So in 1st search it should show unique and after search is proceed with “floor lamp” then it should get results for lamp related and so on

(attaching the collection json)

Product_collection.json (1.4 MB)

Also we want to achieve the same scoring pattern with AutoComplete as we got during text search (Atlas Search - scoring - #8 by Jason_Tran)
So most matching search should get listed first. Like when “floor lamp” is searched then all “floor lamp …” should get high score then “floor mat”

Does anyone have solution

You can try a combination of text and autocomplete with the same search term to see if that works for you.

Please refer to Index Field as Multiple Data Types documentation for more information that may help for this.

Tried combination but getting error, can you check if I’m missing something

[
  {
    $search:
      {
        index: "autoCompleteProducts",
        compound: {
          must: [
            {
              text: {
                query: "floor mats",
                path: "name",
              },
            },
            {
              autocomplete: {
                query: "floor mats",
                path: "name",
                tokenOrder: "sequential",
              },
            },
          ],
        },
      },
  },
  {
    $project:
      /**
       * specifications: The fields to
       *   include or exclude.
       */
      {
        _id: 0,
        name: 1,
        score: {
          $meta: "searchScore",
        },
      },
  },
]

we are getting the results after configuring index option to “positions”. Can you please guide us or provide the query to achieve the result as provided in initial request. we want to show unique values in autocomplete on 1st word then 2nd word onwards it will show natural results. Example: when “floor” is searched then we should get “floor mat”, “floor lamp”…etc. Then when “floor lamp” is typed it will get natural results

1 Like

Did you find solution for your initial request ? I am also looking for similar results. Could you kinldy help on this ?