Search and Sort: How to sort by price when searching by multiple keys in multiple fields

Sample Documents
document1 = {
“product_id”: “1”,
“title”: “sports kit with free cricket ball”,
“keywords”: “sports, cricket, ball”,
“price”: “300”
}
document2 = {
“product_id”: “2”,
“title”: “cricket bat at cheap price”,
“keywords”: “sports, cricket”,
“price”: “50”
}
document3 = {
“product_id”: “3”,
“title”: “sports shoes with free cricket ball”,
“keywords”: “sports, cricket, ball, shoes”,
“price”: “250”
}

Search Keys
Search keys = [‘cricket’, ‘sports’, ‘bat’]

Map function
function (doc, meta) {
var s_search = doc.title.toString()+’ '+doc.keywords.toString();

s_search = s_search.split(",");

for(var i=0;i<s_search.length;i++)
{
sub_searcharray = s_search[i].split(" ");
for(var j=0;j<sub_searcharray.length;j++)
{

emit(sub_searcharray[j], doc);

}
}
}

There’s no straightforward way to search and sort by multiple different fields with views. You can do some tricks with complex keys, but the number of views required quickly grows out of hand, unless you only have a few fields you’re interested in.

Depending on your development timeline, you should either look at N1QL, which will certainly be able to do this, or if you need it right now, at ElasticSearch integration: http://docs.couchbase.com/admin/elastic/elastic-intro.html