Answer the question
In order to leave comments, you need to log in
How to search for an incomplete match in 'mongoose-text-search'?
//event schema
var mongoose = require('mongoose');
var textSearch = require('mongoose-text-search');
var eventSchema = new mongoose.Schema({
description: String,
address: String
}, { collection: 'events' });
eventSchema.plugin(textSearch);
eventSchema.index(
{
description: 'text',
address: 'text'
},
{
name: 'textScore',
weights: {
description: 1,
address: 2
}
}
);
module.exports = mongoose.model('Event', eventSchema);
//Events.js file
app.get('/test/:text', function(req,res) {
var Event = require('../models/Event');
Event
.find(
{ $text : { $search : req.params.text} },
{ score : { $meta: "textScore" } }
)
.sort({ score : { $meta : 'textScore' } })
.exec(function(err, results) {
res.send(results)
// Находит только если "req.params.text" полностью совпадает с текстом в базе пробовал через регулярку аля
// new RegExp(req.params.text, 'i'), в самом mongoose она работает а в этом плагине нет... помогите
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question