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

Logical AND operator in Text Search - would allow combination with logical OR

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Text Search
    • None
    • Environment:
      Ubuntu Linux, MongoDB v3.2

      Hi,

      I would like to combine logical OR and ANDs in a text search, for example:

      "gas" AND ("TTF" OR "Netherlands" OR "Rotterdam")

      In the documentation for $text there is no mention of an AND operator - stackoverflow answers suggest a workaround is to pass multiple phrases to the $search operator, eg.

      db.Examples.find({$text: {$search: "\"gas\" \"TTF\""}})

      However this stops you using OR operators. My current approach is to run two searches, one for "gas" and one for ("TTF" OR "Netherlands" OR "Rotterdam"), returning just the _id field, take the common ids from the two lists and then run a filter query with the result.

      Is there currently a way to combine ORs and ANDs? And if not would it be possible to add an AND operator?

      Thanks for your help,
      Phil

            Assignee:
            Unassigned Unassigned
            Reporter:
            PhillipMarsh Phillip Marsh
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: