couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <...@apache.org>
Subject Re: Weird sorting: _all_docs vs _view
Date Tue, 15 Sep 2015 11:00:02 GMT
Hi Jonas,

I see @rnewson has replied to you on IRC already, just closing this out for posterity.

_all_docs is sorted “raw”, that is by Erlang binary comparison rules (think ascii code
points, but not quite).

Views are sorted using the ICU library, which defines sorting according to the natural language
specified in your locale.

Best
Jan
--


> On 15 Sep 2015, at 12:54, Jonas Weber <mail@jonasw.de> wrote:
> 
> Hi everybody,
> 
> please take a look at the following transcript. It creates a database, inserts some documents
and queries them. My issue is the sorting of _all_docs vs the result of the view: In the first
case, hello leads, while in the second case Hello comes first:
> 
> $ curl http://localhost:5984/
>      {"couchdb":"Welcome","uuid":"a96430b1b7736a09cf6433604a030bd2","version":"1.6.1","vendor":{"name":"The
Apache Software Foundation","version":"1.6.1"}}
> $ curl -X PUT http://localhost:5984/test-ids
>     {"ok":true}
> $ curl -X POST http://localhost:5984/test-ids/_bulk_docs -HContent-type:application/json
-d'{"docs": [{"_id": "Hello"}, {"_id": "hello"}, {"_id": "_design/tst", "views": {"ids": {"map":"function
(doc) { emit(doc._id, 1); }"}}}]}'
>     [{"ok":true,"id":"Hello","rev":"1-967a00dff5e02add41819138abb3284d"},{"ok":true,"id":"hello","rev":"1-967a00dff5e02add41819138abb3284d"},
>      {"ok":true,"id":"_design/tst","rev":"1-e267a159c1b990605f05150480ccc754"}]
> $ curl http://localhost:5984/test-ids/_all_docs
>      {"total_rows":3,"offset":0,"rows":[
>      {"id":"Hello","key":"Hello","value":{"rev":"1-967a00dff5e02add41819138abb3284d"}},
>      {"id":"_design/tst","key":"_design/tst","value":{"rev":"1-e267a159c1b990605f05150480ccc754"}},
>      {"id":"hello","key":"hello","value":{"rev":"1-967a00dff5e02add41819138abb3284d"}}
>      ]}
> $ curl http://localhost:5984/test-ids/_design/tst/_view/ids
>      {"total_rows":2,"offset":0,"rows":[
>      {"id":"hello","key":"hello","value":1},
>      {"id":"Hello","key":"Hello","value":1}
>      ]}
> $
> 
> When I do the same in PouchDB, the results are different (but consistent):
> 
> var db = new PouchDB('test-ids');
> db.replicate.from('http://localhost:5984/test-ids')
> .then(function () { return db.allDocs(); })
> .then(function (docs) { console.log(JSON.stringify(docs.rows)); return db.query('tst/ids');
})
> .then(function (docs) { console.log(JSON.stringify(docs.rows)); })
> 
> gives
> 
> [{"id":"Hello","key":"Hello","value":{"rev":"1-967a00dff5e02add41819138abb3284d"}},{"id":"_design/tst",.....},{"id":"hello","key":"hello","value":{"rev":"1-967a00dff5e02add41819138abb3284d"}}]
> [{"key":"Hello","id":"Hello","value":1},{"key":"hello","id":"hello","value":1}]
> 
> Is this behaviour a bug or a feature? The documentation for views says:
> 	• Text (case sensitive, lowercase first)
> Best regards,
> Jonas Weber

-- 
Professional Support for Apache CouchDB:
http://www.neighbourhood.ie/couchdb-support/


Mime
View raw message