Prioritize certain records over others with Autocomplete

I am using the atlas search autocomplete feature for a collection of Songs in MongoDb.

If I query the song “Santa Claus Is Comin’ To Town” using autocomplete, I get back many versions of this song by many different artists.

A Song in my case has a "isPopular": "true" attribute, if the song is a popular version of the song.

I am looking to prioritize documents that have "isPopular": "true" so that they are returned first in the autocomplete result list. The way I currently have this search configured does not pay attention to this isPopular attribute. How might I boost these popular records?

Here is the index that I defined in Atlas Search:

{
  "mappings": {
    "dynamic": false,
    "fields": {
      "name": [
        {
          "foldDiacritics": false,
          "maxGrams": 7,
          "minGrams": 3,
          "tokenization": "edgeGram",
          "type": "autocomplete"
        }
      ]
    }
  }
}

And here is the query I am using to fetch the results using a compound should query factoring the isPopular.

let results = await Song.aggregate([
      {
        $search: {
          index: "song_autocomplete",
          compound: {
            must: [{
              autocomplete: {
                query: req.query.name,
                path: "name",
                tokenOrder: "sequential",
              }
            }],
            should: [{
              text: {
                query: "true",
                path: "isPopular"
              }
            }],
          }
        },
      },
      {
        $project: {
          name: 1,
          _id: 1,
        },
      },
      {
        $limit: 10,
      },
    ]);

Would appreciate any workaround here so that results that have isPopular show up as the first results.

Hi @Michael_Murphy, welcome to the MongodB community! You should be able to achieve this by customizing the score of results - try playing around with the boost or constant options. This should allow you to increase the score of documents which satisfy "isPopular": "true" so that they get returned at the top of the results list.

Let me know if this helps!

So I’ve been playing around with score priror, but just did so again and it does not seem to be effecting the results or their scores when I $project the scores with the result. The value is the same with or without the score boost or constant for records where isPopular: "true"

$search: {
          index: "song_autocomplete",
          compound: {
            must: [{
              autocomplete: {
                query: req.query.name,
                path: "name",
                tokenOrder: "sequential",
              }
            }],
            should: [{
              text: {
                query: "true",
                path: "isPopular",
                score: {
                  // "constant": { value: 5 }
                  "boost": { value: 5 }
                }
              }
            }],
          }
        },

Am I configuring this incorrectly?