[SERVER-27946] Logical AND operator in Text Search - would allow combination with logical OR Created: 08/Feb/17  Updated: 04/Apr/17  Resolved: 08/Feb/17

Status: Closed
Project: Core Server
Component/s: Text Search
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Phillip Marsh Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu Linux, MongoDB v3.2


Issue Links:
Duplicate
duplicates SERVER-22583 Allow text search to OR exact phrases Backlog
Participants:

 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



 Comments   
Comment by Kelsey Schubert [ 04/Apr/17 ]

Hi PhillipMarsh,

Thanks for your feedback, we'll keep it in mind when we implement this functionality.

Kind regards,
Thomas

Comment by Phillip Marsh [ 08/Feb/17 ]

Hi @Thomas Schubert,

Thanks for your reply.

The linked ticket references combining ORs with ANDs, but in the opposite way to mine (ie. ("gas" AND "TTF") OR ("gas" AND "Netherlands") OR ("gas" AND "Rotterdam")) which should have the same result. Would it be possible to have an AND operator as well, even if it just translated to the OR structure before running the query?

Cheers,
Phil

Comment by Kelsey Schubert [ 08/Feb/17 ]

Hi PhillipMarsh,

Thanks for the improvement request. I've marked this ticket as a duplicate of SERVER-22583, which is a request that looks for the same functionality. Please feel free to vote for SERVER-22583 and watch it for updates.

Kind regards,
Thomas

Generated at Thu Feb 08 04:16:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.