[SERVER-24221] When using phrases in text search other individual terms are not respected Created: 19/May/16  Updated: 20/May/16  Resolved: 20/May/16

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

Type: Bug Priority: Major - P3
Reporter: Faleij Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

db.getCollection('tests').drop()
db.getCollection('tests').createIndex({ someText: "text" })
db.getCollection('tests').insert({ someText: "ssl certificate authority key" })
db.getCollection('tests').find({ $text: { $search: "\"ssl certificate\" authority key" } }) // found one - as expected
db.getCollection('tests').find({ $text: { $search: "\"ssl certificate\" mongodb regex" } }) // found one - same as above - not as expected

Participants:

 Description   

When specifying a text search such as "\"ssl certificate\" authority key"
the individual terms "authority" and "key" is not respected as per the docs.

The $text operator searches for the phrase "ssl certificate" and ("authority" or "key" or "ssl" or "certificate" ).



 Comments   
Comment by Kelsey Schubert [ 20/May/16 ]

Hi Faleij,

Thanks for the report. The behavior you describe matches the documentation you reference.

  • with search criteria of "\"ssl certificate\" mongodb regex" the $text operator searches for the phrase "ssl certificate" AND ("mongodb" OR "regex" OR "ssl" OR "certificate").
  • the text string "ssl certificate authority key" has the phrase "ssl certificate" as well as the terms "ssl" and "certificate".
  • consequently, the boolean expression is True AND (False OR False OR True OR True), which simplifies to True, so the document is returned.

I hope this clarifies this behavior. For MongoDB-related support discussion please post on the mongodb-users group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-users group.

Kind regards,
Thomas

Comment by Faleij [ 19/May/16 ]

If the $search string includes a phrase and individual terms, text search will only match the documents that include the phrase. More specifically, the search performs a logical AND of the phrase with the individual terms in the search string.
https://docs.mongodb.com/v3.2/reference/operator/query/text/

The "logical AND of the phrase with the individual terms" does not seem to be happening.

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