一般来说,我对 CouchDB、Map/Reduce 和 NoSQL 还是很陌生。
我希望你们能指导我如何在我的 Node.js/CouchDB 应用程序上实现非常基本的搜索。
我正在寻找在 CouchDB 文档中搜索某些文本元素。
我在沙发上的大部分文件都采用下面提到的类似格式:
{
"_id": "b001729a2c5cf4100ea50a71ec04e20b",
"_rev": "1-8928ea122d80fd5c1da1c22dfc6ce46e",
"Approved To Publish": "false",
"Article Body": "has retained the Carbon Trust Standard for energy and carbon management.Following a demanding audit process that took place in December 2012, was awarded recertification for the Carbon Trust Standard.This certificate is a mark of excellence in recognition of how well we measure, manage and reduce our carbon emissions.",
"Headline": "Delight retains Carbon Trust Standard"
}
我的搜索键将是例如“碳信托”、“排放”、“卓越认可”等。
我所拥有的是一个临时映射函数,我在 POST 请求中的 Node.js 应用程序的请求正文中使用它,但我确信它不是正确的方法,我希望它是 CouchDB 中的存储视图.
我的地图功能:
function (doc) {
if ('Headline' in doc) {
if (doc['Article Body'].search(/" + req.body.jsonValue + "/i) !== -1
|| doc.Headline.search(/" + req.body.jsonValue + "/i) !== -1) {
var key = doc.Headline,
value = doc;
emit(key, value);
}
}
}
请让我知道我需要做些什么来改进我的方法,或者如果事情不清楚,请告诉我。
问候