incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Barnes <mrtr...@gmail.com>
Subject Re: Key sorting by integer
Date Fri, 12 Mar 2010 01:31:33 GMT
Is there any reason you are storing your numeric values as strings in 
the first place? (In JSON notation 11234 and "11234" are a number and a 
string, respectively)

If you were emitting numbers for that part of the key array, then it 
would sort the way that you're after.

On 12/03/2010 11:16 AM, Chris Stockton wrote:
> Hello,
>
> I am working on the sorting feature of our application, currently
> string sorting is working well, but would like to sort by date and
> integer value as opposed to following the collation rules defined at
> [1]. I have a view function as defined below:
>
>    function(doc) {
>      if(doc.type&&  'model' == doc.type&&  doc.model&&  doc.data)
{
>        for(key in doc.data) {
>          emit([doc.model, key, doc.data[key]], doc._id); }}}
>
> Which index's documents of the following properties:
>    {
>       "_id": "ffeff3a1ba7c20c9a348074387c9f091",
>       "data": {
>           "Rental_id": "12271",
>           "Rental Date": "8/18/2005 4:33",
>           "DVD_id": "3866",
>           "Name": "DEAN SAUER",
>           "Return Date": "8/20/2005 23:10"
>       },
>       "type": "model",
>       "model": "Rental"
>    }
>
> I sort using a call like so:
>    http://<snip>:58945/db_1/_design/model/_view/getByModelColumnValue?skip=0&limit=50&include_docs=true&descending=true&endkey=["Rental","Rental_id"]&startkey=["Rental","Rental_id",{}]
>
> This returns a result such as:
>    9992, 9991, 9990, 999, 9989, 9988
>
> This is expected according to the collation rules and string sorting.
> However we would like to achieve the sorting our users expect for
> integer column types, such as:
>    9992, 9991, 9990, 9989, 9988, 999
>
> Our immediate thought for a solution for this was to add zero
> left-padding to our integer columns; which would however be a
> significant UI and back end change that we would like to avoid if
> possible.
>
> Thank you for your time,
>
> -Chris
>
> [1] View_Collation -
> http://wiki.apache.org/couchdb/View_collation?action=show&redirect=ViewCollation
>

Mime
View raw message