如何使用 couchdb-lucene 在 CouchDB 中索引数组(标签) [英] How-to index arrays (tags) in CouchDB using couchdb-lucene
问题描述
设置:
我有一个使用 CouchDB 的项目.文档将有一个名为标签"的字段.这个tags"字段是一个字符串数组(例如,tags":[tag1",tag2",etc"]).我正在使用 couchdb-lucene 作为我的搜索提供程序.
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.
问题:
用什么函数可以让couchdb-lucene对tags"的元素进行索引?
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.
推荐答案
好吧,我想通了之后就很容易了.请注意 $ 字符对代码没有意义,在这种情况下我的字段只是以 $ 开头.为将来有此问题的任何人发布答案.
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;
}
这篇关于如何使用 couchdb-lucene 在 CouchDB 中索引数组(标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!