我正在为一家网店建立一个推荐系统.购物历史记录保存在沙发数据库中.我正在通过map-Reducts for each 用户和产品创建一个视图,即该产品的购买量.减go 的部分在于求和.
// map
const onCheckout = (doc) => {
const { username, items } = doc;
// once a checkout is done (i.e. history db is populated)
// map every items bought
items.map((item) => emit([username, item.name], item.quantity));
};
然后,我可以获取我的推荐服务并获取视图.
router.get("/recommendation/user", jwt, (req, res) => {
const { username } = req.auth;
history
.view("on-checkout__user", "items_bought", {
group: true,
})
.then((body) => {
console.log(body.rows);
res.status(200).json({ content: body.rows });
})
.catch((err) => res.send(err));
});
This gives me the following results
第一个密钥是用户名,然后是产品.价值是用户购买该产品的总数量.然而,我希望过滤器只针对特定的用户(在头中使用JWT进行请求的过滤器,例如,只针对名为"potiron"的用户).我知道我可以在视图函数的参数中传递一个键,我try 了{key: "potiron"}
,但它不起作用.还有别的办法吗?