Re: Proper way to use views to search for a string in document arrays

36 views
Skip to first unread message

Jens Alfke

unread,
Apr 21, 2014, 12:04:13 AM4/21/14
to mobile-c...@googlegroups.com

On Apr 20, 2014, at 6:17 PM, Ragu Vijaykumar <ra...@scrxpt.com> wrote:

Document2 {
tags: [tagA, tagC]
}

The user types in a search term, and I want to return all documents who contain the search term as a tag. So if the user types in "tagA", I would be able to get back Document1 and Document2, but if they typed "tagB", it would only return Document1.

I forget which platform you’re using, so I’ll write it in pseudo-JavaScript:
function(doc) {
for (tag in doc.tags)
emit(tag, null);
}
Then just query with startKey = endKey = the desired tag.

—Jens

Ragu Vijaykumar

unread,
Apr 21, 2014, 2:14:54 AM4/21/14
to mobile-c...@googlegroups.com
Ah, I didn't realize you can call emit more than once in a block. Thanks!
Reply all
Reply to author
Forward
0 new messages