Home > Blockchain >  How to search like LinkedIn/Facebook in mongoose?
How to search like LinkedIn/Facebook in mongoose?

Time:02-21

If user searches for "John Banglore" or "Banglore John" then they should get John from Banglore at first position in result and then other related results. how to do it ?

UserModel.js{ name:String, city:String }

and I have tried by splitting query string then converting to regex and then search but it is not returning John from Banglore at first position in result.

Backend - Node.js Database - MongoDB Module - mongoose

CodePudding user response:

This could be solved with a simple approach for your specific use case Where you split the name on the space character and do a set of regexes based on that. Although that solves this case. You will likely run into other cases where the fuzzy matching capabilities are limited. It may be better to look into a Inverted Index such as elastic search for enhanced search capabilities.

  • Related