incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From J Chris Anderson <jch...@apache.org>
Subject Re: My first few days of using couchdb
Date Sun, 25 Jul 2010 19:59:19 GMT

On Jul 25, 2010, at 12:50 PM, Mikeal Rogers wrote:

> Why not just doc.tags.forEach(function(t) {emit(t,1)})
> 
> Then do a POST query to the view with {"keys":["holiday", "camping"],
> "include_docs":true}
> 

That'll give OR but not AND. He'd then have to do the intersection on the client. I do think
this is still a pretty pragmatic solution as long as there aren't too many docs tagged "camping"
and not "holiday"

> Wrote this code on my iPhone so I hope it's correct. :)
> 
> On Sunday, July 25, 2010, J Chris Anderson <jchris@gmail.com> wrote:
>> 
>> On Jul 25, 2010, at 10:18 AM, Joe Bloggs wrote:
>> 
>>> I have been impressed with couchdb so far but I have now hit the first problem
>>> that I cannot see how to resolve easily.
>>> 
>>> I have a few test documents with a photo attached to each. I want to tag these
>>> photos so I have a field called tags. This tag field may contain 1 or many tags.
>>> 
>>> For example:-
>>> 
>>> [ "holiday","camping"]
>>> or
>>> ["holiday","skiing"]
>>> 
>>> I can easily create a view that allows me to search the tags with ?key="holiday"
>>> however I cannot work out how to select photos which contains both tag1 and
>>> tag2.
>> 
>> the simplest way to do this is with 2 view queries, and compute the intersection.
>> 
>> the other option is to emit the tags list in all possible permutations (you can cut
them down a bit if you only emit them sorted by alpha order). this will make a much larger
index, especially if docs tend to have more than 3 or so tags.
>> 
>>> 
>>> Any guidance would be appreciated.
>>> 
>>> Regards
>>> 
>>> Robin
>>> 
>>> 
>> 
>> 


Mime
View raw message