用于固定类别查询的 CouchDB

发布于 2024-11-23 20:38:18 字数 628 浏览 0 评论 0原文

我的 CouchDB 中有这样的文档:

{
  "_id": "0cb35be3cc73d6859c303fa3200011d2",
  "_rev": "1-f6e356bbf6ab09290aae11132af50d66",
  "adresse": "Bohrgaß 10 /",
  "plz": 56814,
  "ort": "Faid /",
  "kw": 2.32,
  "traeger": "SOL"
  ...
}

某些属性有预定义的类别,例如 traeger:“SOL”、“BIO”、“WAS”;千瓦:<2、2-5、5-20、20-100;请:56814,请:56815; ...

我必须能够有效地查询每个类别的文档总数,并且 特定条件下的文档总数和文档本身。例如,

  1. 在 traeger =“SOL”条件下,类别 kw <2(以及所有其他 kw 类别)中有多少文档
  2. 在 plz 条件下,类别 traeger =“SOL”(以及所有其他 traeger 类别)中有多少文档=56814 且 kw < 2

用户可以选择他喜欢组合的类别。类别是固定的。还将有更多的属性和类别。

其映射/归约函数会是什么样子?

马塞尔

I have documents like this in my CouchDB:

{
  "_id": "0cb35be3cc73d6859c303fa3200011d2",
  "_rev": "1-f6e356bbf6ab09290aae11132af50d66",
  "adresse": "Bohrgaß 10 /",
  "plz": 56814,
  "ort": "Faid /",
  "kw": 2.32,
  "traeger": "SOL"
  ...
}

There are predefined categories for certain attributes e.g. traeger: "SOL", "BIO", "WAS"; kw: <2, 2-5, 5-20, 20-100; plz: 56814, plz: 56815; ...

I have to be able to efficiently query the total number of docs for every category and
the total number of docs and the docs itself under certain conditions. E.g.

  1. How many docs are in the category kw <2 (and all other kw categories) under the condition traeger = "SOL"
  2. How many docs are in the category traeger = "SOL" (and all other traeger categories) under the conditions plz=56814 AND kw < 2

The user can select which catagories he likes to combine. The categories are fix. There also will be more attributes and catagories.

How would map/ reduce functions for this look like?

Marcel

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

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

发布评论

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

评论(1

寄离 2024-11-30 20:38:18

由于您要对文档进行计数,因此您的归约函数只是内置计数。您的地图功能需要发出用户要搜索的适当键。最后,当查询视图时,必须选择适当的组级别。

示例:您可以使用组合键 ["traeger", "kw"] 创建视图。如果使用 group_level = 2 查询该视图,您将获得 traeger 和 kw 的每种组合的文档数。

如果您只关心traeger“SOL”,则可以使用start_key和end_key参数限制输出。

如果您想知道每个“traeger”类别中的文档数量,无论其“kw”如何,您可以使用 group_level 1 查询该视图。

对于第二个示例,您可以使用键 ["plz"," 创建一个视图kw","traeger"] 并使用 start_key 和 end_key 查询它以将结果限制为 plz=56814 AND kw < 2 并将 group_level 设置为 3。

此处列出了视图的查询选项:

http://wiki.apache。 org/couchdb/HTTP_view_API#Querying_Options

Since you are going to count documents, your reduce function is simply the built-in count. Your map function needs to emit the appropriate keys your users are going to search for. Finally, when the view is queried, the appropriate group level has to be picked.

Example: You can create a view with a composite key ["traeger", "kw"]. If you query that view with group_level = 2, you get the number of documents for each combination of traeger and kw.

If you only care about the traeger "SOL", you can restrict the output with the start_key and end_key parameters.

If you want to know the number of documents in each "traeger" category no matter their "kw", you can query that view with group_level 1.

For your second example, you can create a view with the key ["plz","kw","traeger"] and query it using start_key and end_key to restrict the results to plz=56814 AND kw < 2 and set group_level to 3.

Querying options for views are listed here:

http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options

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