mongoose-fuzzy-searching icon indicating copy to clipboard operation
mongoose-fuzzy-searching copied to clipboard

Add option to use $all filter instead of $text search

Open rohit-gohri opened this issue 4 years ago • 2 comments

Do you want to request a feature, an issue, or report a bug? feature

What is the current behaviour? Current behavior is to use $text query to search the collection. This gives inaccurate results because of lots of partial matches when searching multiple small common phrases. Eg. when searching "prime bank" it is currently giving results which have only one of these at the top instead of the document which has both.

If the current behaviour is a bug, please provide the steps to reproduce.

What is the expected behaviour? An option where only results are returned which contain all phrases searched. I was thinking how to do this, and instead of using $text search if I instead search the fuzzy array with {$all : } it gives better results.

If this is a feature request, what is the motivation or use case for changing the behaviour? Limiting results when larger search query.

Please mention other relevant information such as Node.js and mongoose version. Node: 14 Mongoose: 5.10

rohit-gohri avatar Dec 16 '20 11:12 rohit-gohri

This isn't completely fleshed out, I will try to create a reproduction repo.

rohit-gohri avatar Dec 16 '20 11:12 rohit-gohri

@rohit-gohri try this https://github.com/evgeniy-skakun/mongoose-fuzzy-searching, there is a search for specific fields using $all

User.fuzzySearch({ query: 'jo', prefixOnly: true, fields: ['firstName'] })
  .then(console.log)
  .catch(console.error);

evgeniy-skakun avatar Feb 05 '21 16:02 evgeniy-skakun