|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.lucene.expressions.js.JavascriptCompiler
public class JavascriptCompiler
An expression compiler for javascript expressions.
Example:
Expression foo = JavascriptCompiler.compile("((0.3*popularity)/10.0)+(0.7*score)");
See the package documentation for
the supported syntax and default functions.
You can compile with an alternate set of functions via compile(String, Map, ClassLoader).
For example:
Map<String,Method> functions = new HashMap<String,Method>();
// add all the default functions
functions.putAll(JavascriptCompiler.DEFAULT_FUNCTIONS);
// add cbrt()
functions.put("cbrt", Math.class.getMethod("cbrt", double.class));
// call compile with customized function map
Expression foo = JavascriptCompiler.compile("cbrt(score)+ln(popularity)",
functions,
getClass().getClassLoader());
| Field Summary | |
|---|---|
static Map<String,Method> |
DEFAULT_FUNCTIONS
The default set of functions available to expressions. |
| Method Summary | |
|---|---|
static Expression |
compile(String sourceText)
Compiles the given expression. |
static Expression |
compile(String sourceText,
Map<String,Method> functions,
ClassLoader parent)
Compiles the given expression with the supplied custom functions. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Map<String,Method> DEFAULT_FUNCTIONS
See the package documentation
for a list.
| Method Detail |
|---|
public static Expression compile(String sourceText)
throws ParseException
sourceText - The expression to compile
ParseException - on failure to compile
public static Expression compile(String sourceText,
Map<String,Method> functions,
ClassLoader parent)
throws ParseException
Functions must be public static, return double and
can take from zero to 256 double parameters.
sourceText - The expression to compilefunctions - map of String names to functionsparent - a ClassLoader that should be used as the parent of the loaded class.
It must contain all classes referred to by the given functions.
ParseException - on failure to compile
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||