How-to index arrays (tags) in CouchDB using couchdb-lucene

喜欢而已 提交于 2019-12-21 02:45:10

问题


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.


回答1:


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;
}



回答2:


Perhaps the syntax has changed, but you can construct a view to search by any item in a document's array:

function(doc) {
  for (var i=0; i<doc.page.length; i++) {
    emit(doc.page[i].url, doc._id);
    }
}


来源:https://stackoverflow.com/questions/2750475/how-to-index-arrays-tags-in-couchdb-using-couchdb-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!