views:

213

answers:

1

The setup:

I have a project that is using CouchDB. The documents will have a field called "tags". This "tags" field is an array of strings (e.g., "tags":["tag1","tag2","etc"]). I am using couchdb-lucene as my search provider.

The question:

What function can be used to get couchdb-lucene to index the elements of "tags"?

If you have an idea but no test environment, type it out, I'll try it and give the result here.

A: 

Well it was quite easy after I figured it out. Please realize that the $ character has no significance to the code, my fields in this case just begin with $. Posted the answer for anyone with this question in the future.

function(doc) {
  var result = new Document();
  for(var i in doc.$tags) {
    result.add(doc.$tags[i]);
  }
  return result;
}
Lucas