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.
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