Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9148

In text searches with $near filter, results don't obey filter

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.0
    • Affects Version/s: 2.4.1
    • Component/s: Geo, Querying, Text Search
    • None
    • ALL

      If the text command is passed a filter with a $near query operator, the result set will include items that don't match the filter. $near needs to be resolved using a geospatial index, and I assume that the matcher currently does not use the index here.

      The expected behavior would be for the search to resolve correctly using both indexes, or to just fail explicitly as unsupported.

      To reproduce:

      db.generated.ensureIndex({"location.coordinates":"2d"})
      db.generated.ensureIndex({t:"text"})
      db.generated.insert({t:"bike",location:{coordinates:[40,7.25]}})
      
      // evaluates to 1:
      db.generated.find({"location.coordinates": { $near: [40,7.25], $maxDistance: 0.01 }}).count()
      
      // evaluates to 0:
      db.generated.find({"location.coordinates": { $near: [-40,7.25], $maxDistance: 0.01 }}).count()
      
      // evaluates to 1:
      db.generated.runCommand("text", { search: "bike", filter: { "location.coordinates": { $near: [40, 7.25], $maxDistance: 0.01 }}}).stats.n
      
      // evaluates to 1 (unexpected):
      db.generated.runCommand("text", { search: "bike", filter: { "location.coordinates": { $near: [-40, 7.25], $maxDistance: 0.01 }}}).stats.n
      

            Assignee:
            hari.khalsa@10gen.com hari.khalsa@10gen.com
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: