-
Type: Improvement
-
Resolution: Duplicate
-
Priority: 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
- duplicates
-
SERVER-22583 Allow text search to OR exact phrases
- Backlog