PROBLEM WITH MONGODB QUERY FOR REGEXP SERACH

44 views
Skip to first unread message

Abhilash Pandey

unread,
Jan 17, 2018, 2:01:02 PM1/17/18
to mongodb-user

PROBLEM WITH MONGODB QUERY FOR REGEXP SERACH:

 

 

I have created indexes based field  on search text .This is the query for normal text search.

 

db.metaobject.find( {$text: { $search:"data"} },{score: { $meta: "textScore" }}).sort( { score: { $meta: "textScore" } } )

 

For normal text output, there is score attribute included with the existing score result.

 

But I am trying to use same approach for REGEXP, but the score attribute in output is showing as 0.

Below is the query used for REGEXP search.

 

db.metaobject.find({ "name": { $regex: /_cm/i }},{score: { $meta: "textScore" }}).sort( { score: { $meta: "textScore" } } )

 

 Now I want to include real score for REGEX output instead of just 0. Is this feature possible in mongo DB. Please check and reply ASAP.

Gaurav Gupta

unread,
Jan 29, 2018, 10:50:50 PM1/29/18
to mongodb-user

Hi Abhilash ,

A regex query looks for a pattern in strings, so the pattern will either match or not match. There could be no similarity score associated with a regex result.

In contrast, “textScore” is a number that indicates how well a document matches the search term.
For more information, see textScore and $text.

Regards,
Gaurav

Reply all
Reply to author
Forward
0 new messages