【问题标题】:MongoDB query for full text search and Geo returning wrong resultMongoDB查询全文搜索和地理返回错误结果
【发布时间】: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


【解决方案1】:

根据2.4 documentation,文本索引不适用于$near:

注意 您不能将需要特殊文本索引的文本命令与需要不同类型的特殊索引的查询运算符结合使用。例如,您不能将文本与 $near 运算符结合使用。

【讨论】:

    猜你喜欢
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 2014-03-13
    • 2016-05-03
    相关资源
    最近更新 更多