当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Equal Precedence View Collation CouchDB?

问题描述:

According to the view collation documentation for CouchDB(

http://wiki.apache.org/couchdb/View_collation), member order does matter for collation. I was wondering if there is a way to disable this attribute such that collation order does not matter? I want to be able to "search" my views such that the documents that are emitted satisfy all the key ranges for the field.

here is some more on view collation for your reference: CouchDB sorting and filtering in the same view

Likewise, if it is possible to set CouchDB such that order does not matter for view collation, the following parameters used for the GET request should only emit docs where doc.phone_number == "ZZZZZZZ" , whereas right now it emits the documents that fall within the range of the first 3 keys and completely ignores the last key. This occurs because the last key has the least precedence in the current collation scheme.

startkey: [null,null,null,"ZZZZZZZ"],

endkey: ["\ufff0","\ufff0","\ufff0","ZZZZZZZZ"],

Sample Mapping Function

var map = function(doc) {

/*

//Keys emitted

1. name

2. address

3. age

3. phone_number

*/

emit([doc.name,doc.address,doc.num_age,doc.phone_number],doc._id)

}

Is this possible, or do I have to create multiple views to perform this? The use of multiple views seems very inefficent.

I've read that CouchDB-Lucene:( How to realize complex search filters in couchdb? Should I avoid temporary views? )would be helpful for complex searching, but that doesn't seem applicable in this case.

网友答案:

Use of multiple views is not inefficient, quite to the contrary : having four views (name, address, age and phone number) will not use significantly more time or memory than having a single view emit everything. It is the simple, straightforward, efficient way of performing "WHERE field = value" queries in CouchDB.

If you are in fact looking for "WHERE field = value AND field2 = value2" queries, then CouchDB will not help you, and you will need to use Lucene.

You need to understand that the collation merely describes how keys are ordered. Even if you could specify any arbitrary collation, you will still have to deal with the fact that CouchDB need you to define an order for the keys, and only lets you query contiguous ranges of keys. This is not compatible with multi-dimensional range queries.

分享给朋友:
您可能感兴趣的文章:
随机阅读: