I'm a Couchdb newbbie.
I've already created a view for doing an "SQL like" on my Products (keys are all Code, and Description words).
function (doc) {
if (doc.type === 'product') {
var words = { };
var text = doc.code + ' ' + doc.description;
text.replace(/\w+/g, function(word) {
words[word.toLowerCase()] = true;
});
for (var w in words) {
emit(w, doc);
}
}
}
My Products also are of a given category. I want to permit the user to get Productso from a given category, and THEN apply that LIKE on that subset
Doing a second view on the products category would solve the filter by category
Question
Which is the couchdb way to do this?
The options i see are:
Build a view named like_by_category, which key is compound [category, word].
Run first view filter by category, run later the like by word, and join manually both resultsets to see which results are on both
Any rope would help me to get out of this hole!
The option 1 is just theory, dont know if it will let me do pagination with ease.
The option 2 also just theory, but i'm no sure about the performance on doing those 2 view runs, specially on mobile devices running http://www.pouchdb.com