couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Wolff <mar...@wolff-hamburg.de>
Subject Re: Brain check on CouchDB views
Date Thu, 12 Nov 2009 23:19:12 GMT
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 ;-)).

CU
  Markus


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 <markus@wolff-hamburg.de>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
>>
> 


Mime
View raw message