[SERVER-76176] $text OR condition on phrases not working Created: 17/Apr/23  Updated: 27/Oct/23  Resolved: 07/Jun/23

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

Type: Bug Priority: Major - P3
Reporter: Abdul Mateen Ahmad Khan Assignee: Arun Banala
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-61259 $or queries with text indexes fail on... Closed
related to DOCS-16189 [Server] Update the text indexes docs... Closed
is related to SERVER-76174 $text OR condition on phrases not wor... Closed
is related to SERVER-76175 $text OR condition on phrases not wor... Closed
Assigned Teams:
Query Integration
Operating System: ALL
Sprint: QI 2023-05-29, QI 2023-06-12
Participants:

 Description   

Hello ,

I think i have found a bug with $text command which is used to invoke the text indexes. The command fails when we are trying to search for multiple phrases and use an OR condition. for example:
find({'$text':{'$search':'\"\"works at company1\" \"Adam\" \"'}})

 This command tokenizes the first phrase and gets documents having 'works' keyword OR 'company1' keyword OR 'Adam' keyword. which is not what we want.  We want the command to get 'works at walee' phrase which is not what the command does.

the AND command:
find({'$text':{'$search':'\"works at company1\" \"Adam\" '}})

works fine and only gets documents which has both the phrase and the keyword doing exact phrase matching .



 Comments   
Comment by Arun Banala [ 07/Jun/23 ]

abdmateen@gmail.com Unfortunately conjunction of multiple phrases is not supported with text indexes. Please refer to the documentation here section in the docs.

MongoDB performs a logical OR search of the terms unless specified as a phrase.

The phrases cannot be used in conjunction with individual terms either.

If the $search string includes a phrase and individual terms, text search will only match the documents that include the phrase.

So I don't think there is any way to use just the text indexes to achieve what you are trying to do. However, I think you can make use of text indexes to match a superset of results that you want to match, then use the regex filter to further filter down the phrases. So something like the below should help

find({$and : [{'$text':{'$search':'company1 Adam'}}, {'path.to.the.text.field': /works at company1/}]})

Comment by Abdul Mateen Ahmad Khan [ 18/Apr/23 ]

just to add context , this is the issue i am talking about if you want another example.

https://stackoverflow.com/questions/28428288/mongodb-logical-or-when-searching-for-words-and-phrases-using-full-text-search

 

I don't think this functionality has been added by mongodb creator team as of yet.

Generated at Thu Feb 08 06:32:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.