【发布时间】:2016-08-26 09:20:18
【问题描述】:
您好,我有以下用例,假设我有一个包含以下字段的 Cloudant 文档:
{
public: false, // Visibility of the doc
permissions: [1,2,3] // List of user IDs that are allowed view access to the doc
}
只有特权用户(如权限字段中所述)才能访问它,或者如果它是公共的(public:true),那么每个用户都可以访问它。
当我试图编写一个搜索索引来检索当前用户有权访问的所有文档时,我的问题就出现了。我的搜索索引将如下所示:
function (doc) {
if (!doc.public) {
doc.permissions.forEach(function(entry) {
index("user_id", parseInt(entry));
});
} else {
index("user_id", ???); // If its public document, how should I index it?
}
}
它适用于将 public 设置为 false 的文档,但我的搜索索引无法返回那些 public 设置为 true 的文档。我的搜索查询如下所示:
q=user_id:1
任何建议,因为我真的需要在 Cloudant 层而不是我的控制器层上实现它。
【问题讨论】: