couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nils Breunese <>
Subject RE: Brain check on CouchDB views
Date Thu, 12 Nov 2009 23:46:35 GMT
You can create a view which has the tag_count as a key or if you don't want to do that, but
want to sort by value, you might want to take a look at couchdb-footrest:
I haven't gotten couchdb-footrest to work yet, but it does promise sorting by value (probably
there is a performance hit somewhere as values are not indexed).

Nils Breunese.

Van: Markus Wolff []
Verzonden: vrijdag 13 november 2009 0:19
Onderwerp: Re: Brain check on CouchDB views

Hi Smrchy,

since the manual states that the query option "descending" only refers
to the key order, and I haven't found anything about ordering by value,
I'd assume that you'd have to do this last step within your application.

In other words, there is no built-in CouchDB equivalent to the SQL
expression "ORDER BY tag_count DESC LIMIT 50".

Instead, you'd have to take the result for all tags sort it by value in
reverse order in your application, and then throw away everything but
the first 50 elements.

In PHP, for example, that would look like:

$reverseOrder = arsort($couchdbResultArray);
$top50 = array_slice($reverseOrder, 0, 50, true);

If there is a way to do it natively in CouchDB, I don't know it yet
(which doesn't mean much ;-)).


Smrchy wrote:
> Hi Markus,
> those simple steps you take are very interesting - i was also running into
> those big reduce problems. Though i admit i am still far away from
> understanding everything about reduce and rereduce.
> In you example how would you give back only the top 50 tags out of all your
> tags in your
> global_tags?group=true
> Is there an easy way for this?
> Patrick
> On Wed, Nov 8, 2006 at 5:41 PM, Markus Wolff <>wrote:
>> Paul Davis wrote:
>>> Markus,
>>> Your thinking is spot on.
>> Wow, that's a first :-P
>>  The short answer is no. The long answer is probably not unless you
>>> know which tags you want in the OR beforehand when you build the view.
>>> The only other way is to use an external indexer.
>>> The reasoning is that boolean logic like this is gonna require
>>> multiple index traversals which CouchDB doesn't allow. As such, the
>>> best answer is either do the logic client side with some effort, or
>>> use an external indexer like couchdb-lucene.
>> Thanks for clearing that up, having confirmed that, I feel confident to
>> proceed in my endeavours ;-)
>> CU
>>  Markus

De informatie vervat in deze  e-mail en meegezonden bijlagen is uitsluitend bedoeld voor gebruik
door de geadresseerde en kan vertrouwelijke informatie bevatten. Openbaarmaking, vermenigvuldiging,
verspreiding en/of verstrekking van deze informatie aan derden is voorbehouden aan geadresseerde.
De VPRO staat niet in voor de juiste en volledige overbrenging van de inhoud van een verzonden
e-mail, noch voor tijdige ontvangst daarvan.

View raw message