请问mongodb也可以提取‘关键字’来搜索查询么?
-
oracle 有模糊查询 like ‘%关键字%’,mongodb的关键字模糊查询是怎样使用的?
-
範例:
db.News.insert([{
"Subject": "123",
"Content": "abc"
},{
"Subject": "456",
"Content": "def"
},{
"Subject": "MongoDB Full Text Search",
"Content": "Yesterday we released the latest unstable version of MongoDB; the headline feature is basic full-text search. You can read all about MongoDB's full text search in the release notes.This blog had been using a really terrible method for search, involving regular expressions, a full collection scan for every search, and no ranking of results by relevance. I wanted to replace all that cruft with MongoDB's full-text search ASAP. Here's what I did."
}]);
db.News.ensureIndex({
Subject: "text",
Content: "text"
});
db.News.aggregate({$match:{$text:{$search:"latest"}}});
-
或
db.News.find({Subject: /Searc/}) //like '%Searc%'
db.News.find({Subject: /^aa/}) //like 'aa%'
db.News.find({Subject: /bb$/}) //like '%bb'
-
1. MongoDB支持正则表达式,如同like,但是效能较差
2. 还有提供全文检索(text search),效能较佳,但是只支持特定语言,中文是不支持的,这里不支持的意思是,你必须输入分隔符间的完整字段
eg: mongodb的关键字模糊查询是怎样使用的。---->你必须把所有的字都输入,才查询的出来,仅输入"关键"是搜寻不出来的
但是如果仍需要使用,可以使用分词工具,将需要查询的文本,分词后存入另一个字段,之后对这个字段进行全文检索
可参考本帖下載内容已隐藏,请登入以查看隐藏内容!