Friday, 15 November 2019

Mongoose question - How to search full text and score the quality of the result

I'm working on a small search bar for a database of a two field model. Just a body of text and an _id.there's a couple of thousand of them.So far, I manage to either look for the exact query, withModel.find({ $text: { $search: `\"${query}\"` } }) or every single match between the query and the db with: Ad.find({ //resultados sin quotes $text: { $search: query } }) with the second option, if i search for "a potato and a tomato" the result will be every text that has at leas one match: "a", "potato", "and", "tomato"and the order is apparently decided by first whatever is found first, so the first result my be waaaaay worse than the last resultIs there any way for me to give every result a score to order things up? like by number of matches or somethingReally, anything at all.Thanks!

Submitted November 16, 2019 at 01:30AM by ImtheDr

No comments:

Post a Comment