用于固定类别查询的 CouchDB
我的 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; ...
我必须能够有效地查询每个类别的文档总数,并且 特定条件下的文档总数和文档本身。例如,
- 在 traeger =“SOL”条件下,类别 kw <2(以及所有其他 kw 类别)中有多少文档
- 在 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.
- How many docs are in the category kw <2 (and all other kw categories) under the condition traeger = "SOL"
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您要对文档进行计数,因此您的归约函数只是内置计数。您的地图功能需要发出用户要搜索的适当键。最后,当查询视图时,必须选择适当的组级别。
示例:您可以使用组合键 ["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