Skip to content

Instantly share code, notes, and snippets.

@ssp
Created June 20, 2013 13:30
Show Gist options
  • Save ssp/5822685 to your computer and use it in GitHub Desktop.
Save ssp/5822685 to your computer and use it in GitHub Desktop.
/*
Based on example script for indexing everything from
https://github.com/rnewson/couchdb-lucene
*/
function(doc) {
var result = new Document();
if (!doc._id.match(/^(_design)/)) {
function index(obj, keyPrefix) {
for (var key in obj) {
var value = obj[key];
switch (typeof(value)) {
case 'object':
index(value, (keyPrefix ? keyPrefix + "." : "") + key);
break;
case 'function':
break;
default:
result.add(value);
var fieldName;
if (obj.constructor === Array) {
fieldName = keyPrefix;
}
else {
fieldName = (keyPrefix ? keyPrefix + "." : "") + key;
}
result.add(value, {"field":fieldName , "store":"yes"});
break;
}
}
};
index(doc, "");
if (doc._attachments) {
for (var i in doc._attachments) {
result.attachment("default", i);
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment