我们正在编写一个 django 应用程序,该应用程序允许用户在他们之间发送私人消息,以及向组发送消息,并且正在寻求实现每个用户定制的搜索功能,以便每个用户都可以搜索和查看消息他们收到了。
我们如何提供为每个用户定制的搜索体验?有些消息是作为组的一部分发送给数千个用户的线程的一部分,而其他消息可能是在 2 个用户之间发送的私人消息,甚至其他消息可能是“待定”消息,等待审核。
我们是否对过滤器进行硬编码,以确定用户是否可以在我们发送到 ElasticSearch 的每个查询中查看消息,或者如果消息发送到有 1000 个成员的组,我是否将 1000 个相同的文档添加到 ElasticSearch,唯一改变的是接受者?
更新
所以这里有一条单独的消息,它的序列化形式是序列化的:
{
"snippet": "Hi All,Though Marylan...", // Friendly snippet, this will be needed in the result
"thread_id": 28719, // Unique ID for this thread
"thread_title": "Great Thread Title Here", // Title for the thread, will be used to diplay in search results
"sent_at": "2015-03-19 07:28:15.092030-05:00", // Datetime the message was originr
"text": "Clean Message Test Here", // Text to be queryable
"pending": false, // If pending, this should only appear in the search results of the sender
"id": 30580, // Unique ID for this message across the entire
"sender": {
"sender_is_staff": false, // If the sender is a staff member or not (Filterable)
"sender": "Anna M.", // Friendly name (we'll need this to display on the result page)
"sender_guid": "23234304-eeee-bbbb-1234-bfb19d56ad68" // Guid of sender (necessary to display a link to the user's profile in the result)
},
"recipient" {
"name": "", // Not filled in for group messages
"recipient_guid": "" // Not filled in for group messages
}
"type": "group", // Values for this can be 'direct' or 'group'
"group_id": 43 // This could be null
}
用户应该能够搜索:
- 他们是“发件人”的所有消息
- 其 GUID 位于“收件人”区域的所有邮件(并且“类型”为“直接”)
- 发送到他们所属的组 ID 的所有消息都不是待处理的(尽管它们可能是 100 个组的成员,所以它可能是 [10,14,15,18,25,44,50,60, 75,80,81,82,83,...])
在 SQL 中SELECT * FROM messages WHERE text contains 'query here' AND (sender.guid = 'my-guid' OR recipient.guid = 'my-guid' OR (group_id in [10,14,15,18,25,44,50,60,75,80,81,82,83,...] AND pending != True))