couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: View to show top tags
Date Sun, 08 Nov 2009 20:19:36 GMT
On Sun, Nov 8, 2009 at 12:57 AM, Smrchy <smrchy@gmail.com> wrote:
> The example you mention does not work at all (throws an internal JSON error)
> while this example:
>
> http://wiki.futuretoby.com/Retrieve_The_Top_N_Tags_in_CouchDB
>
> does run but the results are not anywere near right. If i modify the map
> function to only use a subset of the docs in my DB the values seem to get
> closer to the real count.

The proper strategy is to iterate over the tags and emit each one as a
key, with whatever value you want (null is fine).

Then use one of the built-in reduce functions by setting your reduce
function source code to:

_count

Query with group=true and you will get for each tag, the total count
of useage. You will have to sort the results on the client. if the
result is too large to sort on the client, I'd suggest you copy it to
another Couch database, and use a view on that data to sort it by
value.

Chris

>
> On Sat, Nov 7, 2009 at 5:03 PM, Nils Breunese <N.Breunese@vpro.nl> wrote:
>
>> Check out the wiki, it has an example for exactly your use case:
>> http://wiki.apache.org/couchdb/View_Snippets#top_n_tags
>>
>> Nils Breunese.
>> ________________________________________
>> Van: Smrchy [smrchy@gmail.com]
>> Verzonden: zaterdag 7 november 2009 16:52
>> Aan: user@couchdb.apache.org
>> Onderwerp: View to show top tags
>>
>> I just started with CouchDB trying to migrate a current project over.
>>
>> My database consists of 200K+ documents and each document contains a field
>> like this:
>>
>> "Taglist": [
>>       "London",
>>       "Travel",
>>       "Hotel",
>>       "Europe"]
>>
>> What would be the best way to display the top n-tags of all the documents.
>> Does anybody have an example for this task?
>>
>> Thank you
>> Patrick
>>
>> 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.
>>
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Mime
View raw message