Show / Hide Table of Contents

    Class JavascriptCompiler

    An expression compiler for javascript expressions.

    Inheritance
    System.Object
    JavascriptCompiler
    Namespace: Lucene.Net.Expressions.JS
    Assembly: Lucene.Net.Expressions.dll
    Syntax
    public class JavascriptCompiler : object
    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);

    This is a Lucene.NET EXPERIMENTAL API, use at your own risk

    Fields

    | Improve this Doc View Source

    DEFAULT_FUNCTIONS

    The default set of functions available to expressions.

    Declaration
    public static readonly IDictionary<string, MethodInfo> DEFAULT_FUNCTIONS
    Field Value
    Type Description
    IDictionary<System.String, MethodInfo>
    Remarks

    The default set of functions available to expressions.

    See the Lucene.Net.Expressions.JS for a list.

    Methods

    | Improve this Doc View Source

    Compile(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

    | Improve this Doc View Source

    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

    IDictionary<System.String, MethodInfo> functions

    map of 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 and can take from zero to 256 parameters.

    Exceptions
    Type Condition
    ParseException

    on failure to compile

    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)