Class JavascriptCompiler
An expression compiler for javascript expressions.
Inheritance
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 Lucene.Net.Expressions.JS for the supported syntax and default functions.
You can compile with an alternate set of functions via Compile(String, IDictionary<String, MethodInfo>). For example:
IDictionary<string, MethodInfo> functions = new Dictionary<string, MethodInfo>();
// add all the default functions
functions.PutAll(JavascriptCompiler.DEFAULT_FUNCTIONS);
// add sqrt()
functions.Put("sqrt", (typeof(Math)).GetMethod("Sqrt", new Type[] { typeof(double) }));
// call compile with customized function map
Expression foo = JavascriptCompiler.Compile("sqrt(score)+ln(popularity)", functions);
Fields
| Improve this Doc View SourceDEFAULT_FUNCTIONS
The default set of functions available to expressions.
Declaration
public static readonly IDictionary<string, MethodInfo> DEFAULT_FUNCTIONS
Field Value
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Reflection.MethodInfo> |
Remarks
The default set of functions available to expressions.
See the Lucene.Net.Expressions.JS for a list.
Methods
| Improve this Doc View SourceCompile(String)
Compiles the given expression.
Declaration
public static Expression Compile(string sourceText)
Parameters
Type | Name | Description |
---|---|---|
System.String | sourceText | The expression to compile |
Returns
Type | Description |
---|---|
Expression | A new compiled expression |
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 |
---|---|---|
System.String | sourceText | The expression to compile |
System.Collections.Generic.IDictionary<System.String, System.Reflection.MethodInfo> | functions | map of System.String names to functions |
Returns
Type | Description |
---|---|
Expression | A new compiled expression |
Remarks
Compiles the given expression with the supplied custom functions.
Functions must be public static
, return System.Double and
can take from zero to 256 System.Double parameters.
Exceptions
Type | Condition |
---|---|
ParseException | on failure to compile |