3

我正在使用 Cloudant 构建一个消息传递系统,由“消息”和“成员资格”文档组成:

留言文件:

{"_id":"1","type"="message","group":"a","text":"this is message 1"},
{"_id":"2","type"="message","group":"a","text":"this is message 2"},
{"_id":"3","type"="message","group":"b","text":"this is message 3"},
...

会员文件:

{"_id":"a","type"="membership","user":"joe","group":"a"},
{"_id":"b","type"="membership","user":"bob","group":"a"},
{"_id":"c","type"="membership","user":"bob","group":"b"},
...

每条消息都与一个组相关联。一个用户可能拥有数百个不同组的成员资格。

我想代表特定用户对消息文本执行全文搜索。该应用程序要求用户不得看到来自他们不是其成员的组的消息。

如何进行仅返回来自特定用户所属组的消息的全文搜索?

4

1 回答 1

2

您可以尝试通过创建一个智能搜索字符串来做到这一点。要设置它,当您编写搜索索引函数时,索引消息的组以及消息文本。例如:

function(doc){
  index("group", doc.group);
  index("text", doc.text);
}

然后,在查询该索引时,使用lucene 语法构建一个包含所有用户成员资格的搜索字符串。

(group:a or group:b or group:c or ...) and text:"search string goes here"
于 2013-09-03T14:47:37.467 回答