Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Last active August 29, 2015 14:03
Show Gist options
  • Save Haraldson/fed20ebee0bdb7ee651b to your computer and use it in GitHub Desktop.
Save Haraldson/fed20ebee0bdb7ee651b to your computer and use it in GitHub Desktop.
Cloudant indexing
function(doc)
{
if(doc.docType == 'issue')
{
var indexProperties = function(properties)
{
for(var i = 0; i < properties.length; i++)
{
var property = properties[i];
if(doc[property])
index(property, doc[property], { store: 'yes' });
}
};
var indexPropertiesWithFallbackValue = function(properties)
{
for(var property in properties)
{
var value = property in doc ? doc[property] : properties[property];
index(property, value, { store: 'yes' });
}
};
index('default', doc.title);
indexProperties(
[
'title',
'publicationId',
'liveStartDate',
'liveEndDate',
'created',
'type',
'docType'
]);
indexPropertiesWithFallbackValue(
{
published: true,
scheduled: false
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment