【问题标题】:Mangoosastic Full Text Search via Telegram Bot通过 Telegram Bot 进行 Mangoosastic 全文搜索
【发布时间】:2018-04-16 21:29:48
【问题描述】:

我有一个来自 Telegram Bot 的 msg.text 变量,msg.text 是 = 我的架构名称,我应该如何获取包含用户输入的单词的名称?

架构:

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
});

例如,在我的数据库中,我有 {rockbookpre rockCatrock afterpre rock after} 和用户msg.txt = ro 我应该如何获取和console.log 单词包含roin node.js 项目:

我需要得到:
rock
pre rock
rock after
pre rock after

【问题讨论】:

    标签: javascript full-text-search mongoosastic


    【解决方案1】:

    使用原生 MongoDB 正则表达式解决了我的问题

    parentSchema.index({ name: 'text' });
        Mq.find(
            { "name": { "$regex": "ro", "$options": "i" } },
            function(err,docs) { 
            } 
        );
    

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 2017-12-09
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      • 2019-11-18
      相关资源
      最近更新 更多