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

Setup:

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

Question:

What function can I use to get couchdb-lucene to index tag elements?

If you have an idea, but there is no test environment, enter it, I will try it and give the result here.

+4
source share
2 answers

Well, that was pretty easy after I figured it out. Please understand that the $ symbol does not matter for the code, my fields in this case begin with $. Wrote an answer for anyone who has this question in the future.

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

The syntax may have changed, but you can build a view to search on any element of the document array:

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

Source: https://habr.com/ru/post/1308549/


All Articles