This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
607 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
|
||
* better lifecycle management (couchdb keeps killing our java process when it thinks a query is too slow, this prevents ever building a decent FieldCache for sorting, etc). | ||
* use javascript to let couchdb user to program output transformation rather than current blanket strategy | ||
* indexer as updater process | ||
* searcher as external | ||
* sort cache can take too long to build, respond with keep-alive messages. | ||
* revisit numeric handling (it's too surprising) | ||
* document rhino integration | ||
* code tidy in general. | ||
* add a _status uri that lets you see index state/progress. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.apache.couchdb.lucene; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.ContextFactory; | ||
import org.mozilla.javascript.Function; | ||
import org.mozilla.javascript.Scriptable; | ||
|
||
public final class Rhino { | ||
|
||
private final ContextFactory contextFactory = new ContextFactory(); | ||
|
||
private final Context context; | ||
|
||
private final Scriptable scope; | ||
|
||
private final Function userFun; | ||
|
||
private final Function systemFun; | ||
|
||
private final String fun; | ||
|
||
public Rhino(final String fun) throws IOException { | ||
this.fun = fun; | ||
this.context = contextFactory.enterContext(); | ||
context.setOptimizationLevel(9); | ||
scope = context.initStandardObjects(); | ||
|
||
// compile user-defined function. | ||
this.userFun = context.compileFunction(scope, fun, "userFun", 0, null); | ||
|
||
// compile system function. | ||
this.systemFun = context.compileFunction(scope, | ||
"function(json,filter) { var doc=JSON.parse(json); doc=filter(doc); return JSON.stringify(doc); }", | ||
"systemFun", 0, null); | ||
|
||
// add JSON parser. | ||
context.evaluateString(scope, loadJSONParser(), "json2", 0, null); | ||
} | ||
|
||
private String loadJSONParser() throws IOException { | ||
final InputStream in = Rhino.class.getClassLoader().getResourceAsStream("json2.js"); | ||
try { | ||
return IOUtils.toString(in, "UTF-8"); | ||
} finally { | ||
in.close(); | ||
} | ||
} | ||
|
||
public String parse(final String doc) { | ||
return (String) systemFun.call(context, scope, null, new Object[] { doc, userFun }); | ||
} | ||
|
||
public void close() { | ||
Context.exit(); | ||
} | ||
|
||
public String toString() { | ||
return fun; | ||
} | ||
|
||
} |
Oops, something went wrong.