Question

I'm using CouchDB-Lucene for retrieving data from some of my tables in my database. The thing is that I have to parse that data to know which ones I want to put in my lucene index.

So, I thought that I could use a class that I already wrote to process the data. And that I could use CouchApp directives to add this class in my index function.

The result looks like this:

//Index Function
function (doc) {
   var myClass = new MyClass(doc.Data);
   var ret = new Document();

   ret.add(myClass.getResult());

   return ret;
}

//CouchApp directives:
//! vendor/couchapp/MyClass.js

When I look at my design document, it seems that all the code is correctly added, but when I execute a search, lucene says that "MyClass is not defined".

If I try to copy/paste all "MyClass" code manually (and therefore no longer using the CouchApp directive), lucene says that my document has an incorrect ending.

What am I missing?


EDIT: I removed all my real function code which has no point in the issue.

Was it helpful?

Solution 2

I found the solution to my issue:

I have to put my external code INSIDE my index function:

//Index Function
function (doc) {
   var myClass = new MyClass(doc.Data);
   var ret = new Document();
   ret.add(myClass.getResult());

   return ret;

   //CouchApp directives:
   //! vendor/couchapp/MyClass.js
}

I don't know why it works without being inside the map function for a couchdb view, but it doesn't for a lucene index function.

Hope it helps! Regards, Mickaël

OTHER TIPS

Is !vendor inlining your MyClass code into the "index" value?

The error you got when you included your MyClass code directly sounds like a Javascript error of your own. CouchDB-Lucene evaluates the string use Rhino which is a full Javascript engine.

Perhaps if you include the full "index" value it will be more obvious.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top