CouchDB Views - emit Keys as JSON & filter based on any attribute -
consider following employee document structure
{ "_id":..., "rev":..., "type":"employee", "fname":..., "lname":..., "designation":..., "department":..., "reportingto":..., "isactive":.., more attributes more attributes }
and following map function in view named "employee"
function(doc) { if (doc.type=="employee") { emit({ "eid":doc._id, "firstname":doc.fname, "lastname":doc.lname, "designation":doc.designation, "department":doc.department, "reportingto":doc.reportingto, "active":doc.isactive }, null ); } };
i want query view based on combination & order of emitted attributes ( query may include few random attributes may duck typing ). possible? if kindly let me know samples or links.
thanks
i've ran same problem few times; can, you'll have index each (not in 1 hash you've done). through whole thing in value emit. can inefficient, gets job done. (see link: view snippets)
i.e.:
function(doc) { if (doc.type=="employee") { emit(["eid",doc.values.eid], doc.values); emit(["firstname", doc.fname], doc.values); emit(["lastname", doc.lname], doc.values); emit(["designation", doc.designation], doc.values); emit(["department", doc.department], doc.values); emit(["reportingto", doc.reportingto], doc.values); emit(["active", doc.isactive], doc.values); } }
this puts "eid" things in same part of tree, etc., i'm not sure if or bad you.
if start needing lot of functionality [field name:]value searches, worth move towards lucene-couchdb setup. several exist, little immature.
Comments
Post a Comment