Javascript 通过Telegram Bot进行的Mangoosistic全文搜索
我有一个Javascript 通过Telegram Bot进行的Mangoosistic全文搜索,javascript,full-text-search,mongoosastic,Javascript,Full Text Search,Mongoosastic,我有一个msg.text变量从电报Bot输入,msg.textis=我的模式名,如何获取包含用户输入的单词的名称 模式: const parentSchema = new Schema({ _id: Number, name: String, }); parentSchema.plugin(mongoosastic, { hosts: [ 'localhost:9200' ] }); const Mq = mongoose.model('Mq',
msg.text
变量从电报Bot输入,msg.text
is=我的模式名,如何获取包含用户输入的单词的名称
模式:
const parentSchema = new Schema({
_id: Number,
name: String,
});
parentSchema.plugin(mongoosastic, {
hosts: [
'localhost:9200'
]
});
const Mq = mongoose.model('Mq', parentSchema);
module.exports = Mq;
bot.onText(/\/search/, (msg) => {
// mangoosastic search Code
});
代码:
const parentSchema = new Schema({
_id: Number,
name: String,
});
parentSchema.plugin(mongoosastic, {
hosts: [
'localhost:9200'
]
});
const Mq = mongoose.model('Mq', parentSchema);
module.exports = Mq;
bot.onText(/\/search/, (msg) => {
// mangoosastic search Code
});
例如,在我的数据库中,我有{rock
,book
,pre-rock
,Cat
,rock after
,以及pre-rock after
}
以及用户msg.txt
=ro
我应该如何获取和console.log单词包含node.js项目中的ro
:
我需要得到:rock
pre-rock
摇滚之后
pre-rock after
我的问题用原生MongoDB regex解决了
parentSchema.index({ name: 'text' });
Mq.find(
{ "name": { "$regex": "ro", "$options": "i" } },
function(err,docs) {
}
);