If my search query is "Caramel Cake", then the search results are ["Caramel Cake", "Red Velvet Cake", "Chocolate Truffle Cake", and many more] using my existing code.
I want the search result to be ["Caramel Cake"]
Existing Code:
const products = await Product.aggregate([
{
$search : {
index: "default",
compound: {
should:[
{
autocomplete:{
query: query,
path: "prodname",
fuzzy: {maxEdits: 2, prefixLength: 2}
}
},
{
autocomplete:{
query: query,
path: "prodcategory",
fuzzy: {maxEdits: 2, prefixLength: 2}
}
}
],
minimumShouldMatch: 1,
}
},
},
{
$project: {
prodname: 1,
prodimages:1,
score: {$meta: "searchScore"},
},
},
{
$sort: {
score: -1,
},
},
{ $limit: 10},
]);