好的,我的目标是对我的集合执行文本搜索,然后过滤那些结果,以确保它们属于我的“甜甜圈”几何图形。mongo站点的示例:

这是最难的部分。孟戈的文档证实,今天你不能把$text和$near的美妙结合起来:
不能将需要特殊地理空间索引的$near运算符与使用不同类型特殊索引的查询运算符或命令组合起来。例如,不能将$near与$text查询组合。
所以..。这是我今天要做的事。请注意,我目前的方法没有实现“甜甜圈”几何(它只是一个直径增长的圆,当用户在地图上“放大”时返回重复的结果)。
var vendorResponse = JSON.parse(body);
var vendorPosts = vendorResponse.postings;
//Get the location of the user
var userLat = req.query.lat;
var userLong = req.query.long;
//Get the item that furthest away from the user
var furthestitem = sortedVendorPosts[sortedVendorPosts.length - 1];
//Calculate the radius of the area
var radius = Math.sqrt( Math.pow((userLat-furthestitem.location.lat), 2) + Math.pow((userLong-furthestitem.location.long), 2) )
PostModel.find({
$text: { $search: heading, $language: 'english' },
$or: mongoCategories,
coordinates :
{ $geoWithin :
{
$centerSphere : [ [ userLong, userLat ] , radius ]
}
}
} , { score: {
$meta: "textScore"
}
}, function (err, results) {
});我曾尝试使用mongos $geoIntersects方法,但我正不由自主地提出这个查询。详细的例子,如何解决芒果目前的限制将是一个上帝-发送!谢谢你们!
发布于 2014-09-23 07:22:40
在我的案例中,似乎有几种解决方案:
我已经联系了Mongodb团队,看看我们什么时候能够跨多个索引执行搜索。希望这能帮上忙!
https://stackoverflow.com/questions/25922965
复制相似问题