【发布时间】:2013-06-06 15:20:58
【问题描述】:
当我们尝试通过 mongo cli 进行搜索时,我们没有得到正确的数据。这是完整的场景:
我们在一个集合中有以下 JSON:
"_id" : 18348,
"Name" : "Applebee's Neighborhood Grill",
"AddressLine1" : "2545 Scottsville Rd, Bowling Green, KY - 42104, United States",
"loc" : {
"lng" : -86.42583465576172,
"lat" : 36.95203399658203
},
"ProfilePicturePath" : "",
"MarketID" : 92,
"TotalFavorites" : 0,
"PriceRating" : null,
"ProfileType" : "R",
"Cuisines" : [ ],
"Rating" : 4
当我们搜索同时提供地理查询和全文的位置时,我们得到的结果不正确。在这种情况下(下)我改变了经度: db.rests.runCommand("text", {search:"Applebee's", filter:{ loc : { $near : [-86.43113708496094,136.963356018066406] , $maxDistance : 1/69 }} } )
我明白了:
{
"queryDebugString" : "applebe||||||",
"language" : "english",
"results" : [
{
"score" : 0.6666666666666666,
"obj" : {
"_id" : 18348,
"Name" : "Applebee's Neighborhood Grill",
"AddressLine1" : "2545 Scottsville Rd, Bowling Green, KY - 42104, United States",
"loc" : {
"lng" : -86.42583465576172,
"lat" : 36.95203399658203
},
"ProfilePicturePath" : "",
"MarketID" : 92,
"TotalFavorites" : 0,
"PriceRating" : null,
"ProfileType" : "R",
"Cuisines" : [ ],
"Rating" : 4
}
}
],
"stats" : {
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"nfound" : 1,
"timeMicros" : 92
},
"ok" : 1
}
我们尝试了以下索引:
db.rests.ensureIndex( { "locs": "2d" } )
db.rests.ensureIndex({Name: "text",AddressLine1: "text"})
db.rests.ensureIndex({Name: "text",AddressLine1: "text"},{"loc":"2d"})
也许我们做错了什么?如果我们不使用地理过滤器并使用其他过滤器(如评级等),它的工作正常。
请帮忙
阿米特
http://www.aquevix.com
【问题讨论】:
-
文本搜索目前仍处于测试阶段(MongoDB 2.4),$near 似乎没有作为过滤器的一部分工作。但是根据this post $geoWithin 正在工作。你可以试试吗?
标签: mongodb geospatial full-text-search