papr icon indicating copy to clipboard operation
papr copied to clipboard

Weighted text search

Open djdembeck opened this issue 3 years ago • 1 comments

Hello,

I'm looking into adding text search with relevance scoring into my project. I see MongoDB has this feature (at least in 4.4+): https://docs.mongodb.com/v4.4/text-search/#sorting

It looks like Papr supports $text and $search already, but not score or .sort(). It also doesn't seem there is an index option in the Papr schema like Mongoose has: https://mongoosejs.com/docs/guide.html#indexes

djdembeck avatar Oct 03 '21 05:10 djdembeck

Not super happy with how I was able to accomplish this, but here it is:

                Author.find(
                    { $text: { $search: name } },
                    { projection: { asin: true, description: true, image: true, genres: true, name: true, score: { $meta: 'textScore' } }, limit: 25, sort: { score: { $meta: 'textScore' } } },
                )

djdembeck avatar Oct 12 '21 19:10 djdembeck