1

我在啤酒设计文档中有一个这样的 map() 函数:

function (doc, meta) {

    if(doc.brewery_id)
    emit([ doc.brewery_id, doc.abv], [doc.name, doc.abv, doc.type, doc.brewery_id, doc.style, doc.category]);
}

我需要使用 2 条规则获取所有文档:

1.[brewery_id] 以“21st”开头

2.[abv] 3-4 之间

我的过滤器是:

startkey=["21st", 3]
endkey=["21st\uefff", 4]

但结果不正确,规则 1 按预期工作,但规则 2 被忽略。请帮我找出问题所在。

谢谢!!!

听说结果

{"total_rows":5891,"rows":[
{"id":"21st_amendment_brewery_cafe-bitter_american","key":["21st_amendment_brewery_cafe",3.6],"value":["Bitter American",3.6,"beer","21st_amendment_brewery_cafe","Special Bitter or Best Bitter","British Ale"]},
{"id":"21st_amendment_brewery_cafe-563_stout","key":["21st_amendment_brewery_cafe",5],"value":["563 Stout",5,"beer","21st_amendment_brewery_cafe","American-Style Stout","North American Ale"]},
{"id":"21st_amendment_brewery_cafe-south_park_blonde","key":["21st_amendment_brewery_cafe",5],"value":["South Park Blonde",5,"beer","21st_amendment_brewery_cafe","Golden or Blonde Ale","North American Ale"]},
{"id":"21st_amendment_brewery_cafe-amendment_pale_ale","key":["21st_amendment_brewery_cafe",5.2],"value":["Amendment Pale Ale",5.2,"beer","21st_amendment_brewery_cafe","American-Style Pale Ale","North American Ale"]},
{"id":"21st_amendment_brewery_cafe-potrero_esb","key":["21st_amendment_brewery_cafe",5.2],"value":["Potrero ESB",5.2,"beer","21st_amendment_brewery_cafe","Special Bitter or Best Bitter","British Ale"]},
{"id":"21st_amendment_brewery_cafe-general_pippo_s_porter","key":["21st_amendment_brewery_cafe",5.5],"value":["General Pippo's Porter",5.5,"beer","21st_amendment_brewery_cafe","Porter","Irish Ale"]},
{"id":"21st_amendment_brewery_cafe-watermelon_wheat","key":["21st_amendment_brewery_cafe",5.5],"value":["Watermelon Wheat",5.5,"beer","21st_amendment_brewery_cafe","Belgian-Style Fruit Lambic","Belgian and French Ale"]},
{"id":"21st_amendment_brewery_cafe-north_star_red","key":["21st_amendment_brewery_cafe",5.8],"value":["North Star Red",5.8,"beer","21st_amendment_brewery_cafe","American-Style Amber/Red Ale","North American Ale"]},
{"id":"21st_amendment_brewery_cafe-oyster_point_oyster_stout","key":["21st_amendment_brewery_cafe",5.9],"value":["Oyster Point Oyster Stout",5.9,"beer","21st_amendment_brewery_cafe","American-Style Stout","North American Ale"]},
{"id":"21st_amendment_brewery_cafe-21a_ipa","key":["21st_amendment_brewery_cafe",7.2],"value":["21A IPA",7.2,"beer","21st_amendment_brewery_cafe","American-Style India Pale Ale","North American Ale"]}
]
}
4

1 回答 1

1

如果您需要按 2 个不同的范围过滤结果,您可以使用 LinQ,但如果您有大量文档,它可能会很慢。所以为了让它更快,你可以做两件事:

  1. 在应用 LinQ“过滤器”缓存结果后,memcached 或 couchbase。

  2. 如果您的数据模型允许您为其中一个范围创建单独的视图,即如果您可以将您的范围之一从键移动到映射功能if,例如:21 日视图:

map: function() { if (doc.subtype === "21sts") emit (doc.abv,null) }

其中具有 subtype == "21sts" 的文档是您可以从视图中获取的文档:

map: function() { emit(doc.brewery_id, null) }

和 startkey="21st",endkey="21st\uefff"。

于 2013-08-06T09:20:52.597 回答