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

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

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • Text Search
    • None
    • Ubuntu Linux, MongoDB v3.2

    Description

      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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: