Class JavascriptCompiler
An expression compiler for javascript expressions.
Inherited Members
Namespace: Lucene.Net.Expressions.JS
Assembly: Lucene.Net.Expressions.dll
Syntax
public class JavascriptCompiler
Remarks
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, IDictionary<string, MethodInfo>). For example:
// instantiate and add all the default functions
IDictionary<string, MethodInfo> functions = new Dictionary<string, MethodInfo>(JavascriptCompiler.DEFAULT_FUNCTIONS);
// add sqrt()
functions["sqrt"] = (typeof(Math)).GetMethod("Sqrt", new Type[] { typeof(double) });
// call compile with customized function map
Expression foo = JavascriptCompiler.Compile("sqrt(score)+ln(popularity)", functions);
Note
This API is experimental and might change in incompatible ways in the next release.
Fields
DEFAULT_FUNCTIONS
The default set of functions available to expressions.
Declaration
public static readonly IDictionary<string, MethodInfo> DEFAULT_FUNCTIONS
Field Value
Type | Description |
---|---|
IDictionary<string, MethodInfo> |
Remarks
The default set of functions available to expressions.
See the package documentation for a list.Methods
Compile(string)
Compiles the given expression.
Declaration
public static Expression Compile(string sourceText)
Parameters
Type | Name | Description |
---|---|---|
string | sourceText | The expression to compile |
Returns
Type | Description |
---|---|
Expression | A new compiled expression |
Remarks
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, IDictionary<string, MethodInfo>). For example:
// instantiate and add all the default functions
IDictionary<string, MethodInfo> functions = new Dictionary<string, MethodInfo>(JavascriptCompiler.DEFAULT_FUNCTIONS);
// add sqrt()
functions["sqrt"] = (typeof(Math)).GetMethod("Sqrt", new Type[] { typeof(double) });
// call compile with customized function map
Expression foo = JavascriptCompiler.Compile("sqrt(score)+ln(popularity)", functions);
Note
This API is experimental and might change in incompatible ways in the next release.
Exceptions
Type | Condition |
---|---|
ParseException | on failure to compile |
Compile(string, IDictionary<string, MethodInfo>)
Compiles the given expression with the supplied custom functions.
Declaration
public static Expression Compile(string sourceText, IDictionary<string, MethodInfo> functions)
Parameters
Type | Name | Description |
---|---|---|
string | sourceText | The expression to compile |
IDictionary<string, MethodInfo> | functions | map of string names to functions |
Returns
Type | Description |
---|---|
Expression | A new compiled expression |
Remarks
Compiles the given expression with the supplied custom functions.
Functions must bepublic static
, return double and
can take from zero to 256 double parameters.
Exceptions
Type | Condition |
---|---|
ParseException | on failure to compile |