如何使用 group_level 将超集键与子集匹配(在 couchdb 中进行子选择?)

发布于 2024-10-20 18:56:13 字数 1165 浏览 3 评论 0原文

如何在 couchdb 中进行子选择,或者如何使用 group_level 将超集键与子集匹配

我有一个非常复杂的问题,希望对那些不仅仅是第一次学习 map/reduce 和 couchdb 的人有一个不太复杂的答案。

我正在开发一个系统,该系统向客户端提供 json 清单,以使用每天更新的内容来配置自身。第一次运行时,客户端使用一些描述性标签(例如:屏幕尺寸、操作系统、位置)注册自己,然后服务器返回一个 group_id。客户端每天使用该 ID 来请求其清单。在后端,我们任意地将共享某些标签的客户分组在一起,以减少我们需要存储/服务的唯一清单的数量。

我们的销售/管理员有一个网络应用程序,他可以在其中设置受众以针对特定群体的特定内容。一个受众可以与多个组重叠。诀窍是,当客户报告以获得新的清单时,我们需要找出最适合该客户群体的受众。最佳匹配受众群体将是其标签是已提交组标签子集的第一个受众群体,例如:

audience1: tagA, tagB, tagC, tagD
audience2: tagA, tagC

group1: tagA, tagB, tagC

该组应匹配受众群体 2,而不是受众群体 1。

如果我们使用受众标签来查找最佳组匹配(换句话说,如果 group.tags 是 Audience.tags 的子集),我可以像这样构建一个真正有效的索引:

[tagA, tagB, tagC], group1._id
[tagA, tagC, tagB], group1._id
[tagB, tagA, tagC], group1._id
[tagB, tagC, tagA], group1._id
[tagC, tagA, tagB], group1._id
[tagC, tagB, tagA], group1._id

并使用 group_level=2 和 key=[tagA , tagC] 将audience2 与索引中的第二行进行匹配。问题是,我不知道如何从另一个方向做到这一点:将 group.tags 与 Audience.tags 的索引进行匹配,其中我们在查询时知道的标签 (group.tags) 是我们试图匹配的标签(audience.tags)

我已经牢牢掌握了简单的 m/r 视图,但我一直在这个问题上遇到死胡同。我遇到的每个解决方案都涉及在我的视图函数中进行某种子选择,这在 couchdb 视图中不起作用......关于如何解决这样的问题有什么想法吗?

希望这个描述有一定道理。

How to do sub selects in couchdb, or, how to match a superset key to a subset using group_level

I have a pretty complex question that hopefully has a not too complex answer to someone who's not just learning map/reduce and couchdb for the first time.

I am working on a system that serves a json manifest to a client to configure itself with content that updates daily. On first run the clients register themselves with a few descriptive tags (say: screen size, OS, location), and the server returns back a group_id. The client uses that id to request its manifest every day. On the backend we arbitrarily group clients together that share certain tags to cut down on the number of unique manifests we need to store/serve.

Our sales/admin person has a webapp where he can setup audiences to target specific content at specific groups. An audience can overlap multiple groups. The trick is, when the client reports in to get a fresh manifest we need to figure out which audience is the best fit to that client's group. The best matching audience will be the first audience who's tags are a subset of the submitted groups tags, e.g.:

audience1: tagA, tagB, tagC, tagD
audience2: tagA, tagC

group1: tagA, tagB, tagC

This group should match audience2, not audience1.

If we were using an audiences tags to find the best group match (in other words, if group.tags were a subset of audience.tags) I could build a really effecient index like so:

[tagA, tagB, tagC], group1._id
[tagA, tagC, tagB], group1._id
[tagB, tagA, tagC], group1._id
[tagB, tagC, tagA], group1._id
[tagC, tagA, tagB], group1._id
[tagC, tagB, tagA], group1._id

and use group_level=2 with key=[tagA, tagC] to match audience2 against the second line in the index. The problem is, I can't figure out how to do this going the other direction: matching a group.tags against an index of audience.tags, where the tags we know at query time (group.tags) are a superset of the tags we are trying to match against (audience.tags)

I've got a firm grasp on simple m/r views, but I keep hiting dead ends on this one. Every solution I come to involves doing some sort of sub select in my view function, which doesn't work in couchdb views... any ideas on how I can attack a problem like this?

Hopefully this decription makes some sense.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香橙ぽ 2024-10-27 18:56:13

我能想到的最简单的解决方案是:对

  • 每个受众的标签进行排序,并将排序后的数组作为视图的键发出。
  • 使用多个键查询视图,即使用 {"keys" 执行 POST :[“key1”,“key2”,...]}

键是您正在查找的所有可能的键,按重要性的相反顺序排列(按指定键的顺序返回行。)同样,键中的标签已排序。

在您的示例中,键可以是:

[tagA, tagB, tagC]
[tagB, tagC]
[tagA, tagC]
[tagA, tagB]
[tagC]
[tagB]
[tagA]

第一个结果是您想要的,因此您可以使用 limit=1。

The easiest solution I can think of is to:

The keys are all the possible keys you are looking for, in reverse order of importance (rows are returned in the order of the keys specified.) Again, the tags in the keys are sorted.

In your example the keys can be:

[tagA, tagB, tagC]
[tagB, tagC]
[tagA, tagC]
[tagA, tagB]
[tagC]
[tagB]
[tagA]

The first result is what you want, so you can use limit=1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文