Is there any way to have multiple tag search implemented in CouchDB? I have documents (posts) each with multiple tags. I need to find posts that have been tagged with an arbitra
I think the following should give you a slightly complicated but solid algorithm -- i.e. it does finds the first results fast, even if you have very many documents. It will probably not perform well in practice :(
Index the documents by each single tag and there document id:
[, ]
E.g. for the documents document
you get
['blue', 'docid1'] ['blue', 'docid2'] ['green', 'docid1'] ['red', 'docid1'] ['yellow', 'docid2']
Now for each tag you want to search for you open a parallel search starting at [tag, ...].
For each tag you maintain a current search position. If the docids at all your searches match, you found a match. If they do not match, try to skip to at least the highest document id via a range search. Repeat.
[It's basically a join.]
The skipping is theoretically fast: We have an index to find these documents. Practically, it's probably slow because of all the round trips to the server. It would be nice to be able to offload that algorithm to a function executed on the server. Is that possible?