Skip to main content

πŸ‘ Exercises

project the score​

πŸ”— Playground link: score not projected

Fix this Playground so that the score being projected is the relevancy score Atlas Search uses for default sorting.

Solution

The score is available in the pipeline $meta context as searchScore.

{"$meta": "searchScore"}
πŸ”— solution

project the score details​

πŸ”— Playground link: add the score details into the results

Enable the score details and project them into the results.

Solution

Enable the score details with this setting in $search:

scoreDetails: true

Include the score details by adding this to $addFields:

"scoreDetails": {
"$meta": "searchScoreDetails"
}
πŸ”— solution

score/sort by the weight field​

πŸ”— Playground link: task: score documents by document field

Set the search (relevance) score to the value of the weight field.

Solution

Use the weight value as the score for the compound operator:

"score": {
"function": {
"path": "weight"
}
}
πŸ”— solution