Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top