let pipeline = [
{
$search: {
index: indexes.CAREERS_SEARCH_INDEX,
compound: {
should: [
{
autocomplete: {
query: searchText,
path: 'role_title',
fuzzy: {
maxEdits: 1,
},
}
},
{
autocomplete: {
query: searchText,
path: 'industry',
fuzzy: {
maxEdits: 1,
},
}
},
{
autocomplete: {
query: searchText,
path: 'overview',
fuzzy: {
maxEdits: 1,
},
}
},
],
},
},
},
];
if (industries && industries.length) {
pipeline.push({
$match: { industry: { $in: industries } },
});
}
pipeline.push({
$limit: limit
});
pipeline.push({
$group: {
_id: null,
search_results: { $push: "$$ROOT" },
matched_count: { $sum: 1 }
}
});
pipeline.push({
$project: {
_id: 0,
search_results: 1,
matched_count: 1
}
});
let results = await CareerModel.aggregate(pipeline);
results = results[0];
data.careers = results.search_results;
data.count = results.matched_count;
return data;
If the results are 40
then limiting the results to 10
changes the matched_count
to 10
as well when it should be 40
actually. The mongoose documentation on atlas search is very limited and does not cover cases like these. If you have faced a similar issue, it would be great if you can just point me in the right direction. Thanks!
如果结果是40,那么将结果限制为10也会将MATCHED_COUNT更改为10,而实际上它应该是40。关于atlas搜索的Mongoose文档非常有限,不包括这样的情况。如果你遇到过类似的问题,如果你能为我指出正确的方向,那就太好了。谢谢!
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!