Reputation: 2015
Suppose I have a JSON object such as [{
address: "Amber 21, Pallet Town, Johto"
value: 8
},
address: "Red 12, Vermilion City, Hoenn"
value: 9
]
A user type Amber street, Johto
in the form.
I'd like to do "smart search" to match the one with the most resemblance (in other words like the best score
if we talk about machine learning) and get the result which is 8
.
Is there any module which does this?
Upvotes: 0
Views: 2810
Reputation: 495
For a simple implementation, just send a request to your server containing the search keyword, example : "mobile"
Then in mongo, target the fields wanted with a regex then return the result.
Front:
// on input change
$.ajax({
method: "GET",
url: "http://searchuri",
data: { search: mysearchinput }
})
.fail(function(err) {
console.log(err.responseJSON);
})
.done(function(data) {
// do stg with your datas
});
Backend:
Datas.find({ productname: { $regex : ".*"+ req.query.search +".*", $options:'i' } }, function(err, result){
return res.status(200).json({result: result})
});
Reference : Search bar with suggestions with nodejs and mongodb
Upvotes: 1
Reputation: 1105
Yes, there's a module which does that really well.
Checkout fusejs
Upvotes: 3