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

XMLWordPrintableJSON

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

      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
              Reporter:
              Phillip Marsh
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: