简体   繁体   中英

MongoDB query for full text search and Geo returning wrong result

When we try to search through mongo cli, we are not getting correct data. Here's the full scenario:

We have the following JSON in a collection:

"_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

When we search where we give BOTH Geo Query and full text, we are getting incorrect result. In this case (below) I changed the longitude: db.rests.runCommand( "text", {search:"Applebee's", filter:{ loc : { $near : [-86.43113708496094,136.963356018066406] , $maxDistance : 1/69 }} } )

I get:

{
    "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
}

We have tried with following indexes:

db.rests.ensureIndex( { "locs": "2d" } )
db.rests.ensureIndex({Name: "text",AddressLine1: "text"})
db.rests.ensureIndex({Name: "text",AddressLine1: "text"},{"loc":"2d"})

Perhaps we are doing something wrong? If we do not use Geo Filter and use other filters like Rating etc, its working fine.

Please help
Amit
http://www.aquevix.com

According to the 2.4 documentation , text indexes do not work with $near:

Note You cannot combine the text command, which requires a special text index, with a query operator that requires a different type of special index. For example you cannot combine text with the $near operator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM