0

我们正在编写一个 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
}

用户应该能够搜索:

  1. 他们是“发件人”的所有消息
  2. 其 GUID 位于“收件人”区域的所有邮件(并且“类型”为“直接”)
  3. 发送到他们所属的组 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))

4

1 回答 1

0

我希望我能正确理解你的问题。

因此,您有一个消息传递系统,其中有 3 种类型的消息(组、2 个用户、主持)。您的目标是允许您的用户搜索所有消息,并可以选择对类型、用户、日期等应用过滤器。

利用 ElasticSearch 的可扩展特性来存储您的可搜索数据。首先,考虑运行 ES 节点的服务器。他们是否有足够的性能资源(内存、CPU、网络、硬盘驱动器速度)来满足您的流量和文档的大小/数量?一旦您决定了服务器规格,您就可以根据需要简单地添加更多来分发数据和处理。

接下来,创建您的消息文档结构。我想你的映射可能看起来像这样:

"message": {
"properties": {
    "id": {
        "type": "long"
    },
    "type": {
        "type": "string"
    },
    "body": {
        "type": "string"
    },
    "from_user": {
        "type": "object",
        "properties": {
            "id": {
                "type": "integer"
            },
            "name": {
                "type": "string"
            }
        }
    },
    "to_user": {
        "type": "object",
        "properties": {
            "id": {
                "type": "integer"
            },
            "name": {
                "type": "string"
            }
        }
    },
    "group": {
        "type": "object",
        "properties": {
            "id": {
                "type": "integer"
            },
            "name": {
                "type": "string"
            }
        }
    },
    "added_on": {
        "type": "date"
    },
    "updated_on": {
        "type": "date"
    },
    "status_id": {
        "type": "short"
    }
}}

您可能希望为“body”和“name”字段创建自定义分析器,以自定义搜索结果以满足您的期望。然后只需编写查询并使用过滤器/排序来允许用户全局搜索或从/到特定用户或组进行搜索。

之后,您只需要在您的数据库和 ES 索引之间架起一座桥梁,以便同步您的消息以进行搜索。同步频率取决于您希望消息多快可供搜索。

好吧,我真的希望我能正确理解你的问题。否则,好吧……

于 2015-03-20T02:19:53.390 回答