MongoDB and fulltext search part of the word

旧城冷巷雨未停 提交于 2020-01-03 05:02:06

问题


I need to find a part of the word, if i search about len its shut find all the words there starting by len.

i'm trying to use fulltext search in MongoDB and its working well when its hit 100% words and not just a part of the words.

Have sombardy a soluion to me to get this issue to working?

Sample code there working:

db.getCollection('product').find({
    '$and' : [{
    '$text': {
        '$search' : 'lenovo', // match word
        '$caseSensitive' : false
    },
    '$text': {
        '$search' : 'y50 b50 y700', // synonym prepared
        '$caseSensitive' : false
    }
    }]
})

Sample code i want to get the same resualt:

db.getCollection('product').find({
    '$and' : [{
    '$text': {
        '$search' : 'len',
        '$caseSensitive' : false
    },
    '$text': {
        '$search' : 'y50 b50 y700',
        '$caseSensitive' : false
    }
    }]
})

Thanks for your time, and hope i can get help for this fulltext search in MongoDB


回答1:


If you want full text search in mongo then you should go with $regex by using this query will be

db.product.find({name:{$regex:/len/i}})

for more you can read the documentation as well. https://docs.mongodb.com/manual/reference/operator/query/regex/



来源:https://stackoverflow.com/questions/38828312/mongodb-and-fulltext-search-part-of-the-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!