CouchDB 是否支持多范围查询? [英] Does CouchDB support multiple range queries?

查看:34
本文介绍了CouchDB 是否支持多范围查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 CouchDB 中实现多个范围查询?对于单范围条件,startkey 和 endkey 组合可以正常工作,但同样的事情不适用于多范围条件.

How are multiple range queries implemented in CouchDB? For a single range condition, startkey and endkey combination works fine, but the same thing is not working with a multiple range condition.

我的View函数是这样的:

My View function is like this:

"function(doc){
       if ((doc['couchrest-type'] == 'Item') 
    && doc['loan_name']&& doc['loan_period']&&    
                      doc['loan_amount']) 
     {  emit([doc['template_id'],
          doc['loan_name'],doc['loan_period'],
           doc['loan_amount']],null);}}"

我需要使用 loan_period > 5 和loan_amount > 30000.我的startkey和endkey参数是这样的:

I need to get the whole docs with loan_period > 5 and loan_amount > 30000. My startkey and endkey parameters are like this:

params = {:startkey =>["7446567e45dc5155353736cb3d6041c0",nil,5,30000],
  :endkey=>["7446567e45dc5155353736cb3d6041c0",{},{},{}],:include_docs => true}  

在这里,我没有得到想要的结果.我认为我的 startkey 和 endkey 参数是错误的.谁能帮帮我?

Here, I am not getting the desired result. I think my startkey and endkey params are wrong. Can anyone help me?

推荐答案

CouchDB 视图是条目的有序列表.对视图的查询会返回该列表的连续切片.因此,不可能应用两个不等式条件.

A CouchDB view is an ordered list of entries. Queries on a view return a contiguous slice of that list. As such, it's not possible to apply two inequality conditions.

假设您的 loan_period 是一个离散变量,这种情况可能最好通过先发出 loan_period 然后为每个周期发出一个查询来解决.

Assuming that your loan_period is a discrete variable, this case would probably be best solved by emit'ing the loan_period first and then issuing one query for each period.

另一种解决方案是使用 couchdb-lucene.

An alternative solution would be to use couchdb-lucene.

这篇关于CouchDB 是否支持多范围查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆