Show / Hide Table of Contents

    Class Expression

    Base class that computes the value of an expression for a document.

    Inheritance
    System.Object
    Expression
    Namespace: Lucene.Net.Expressions
    Assembly: Lucene.Net.Expressions.dll
    Syntax
    public abstract class Expression : object
    Remarks

    Base class that computes the value of an expression for a document.

    Example usage:

    // compile an expression:
    Expression expr = JavascriptCompiler.Compile("sqrt(_score) + ln(popularity)");
    // SimpleBindings just maps variables to SortField instances
    SimpleBindings bindings = new SimpleBindings();
    bindings.Add(new SortField("_score", SortFieldType.SCORE));
    bindings.Add(new SortField("popularity", SortFieldType.INT));
    // create a sort field and sort by it (reverse order)
    Sort sort = new Sort(expr.GetSortField(bindings, true));
    Query query = new TermQuery(new Term("body", "contents"));
    searcher.Search(query, null, 10, sort);
    This is a Lucene.NET EXPERIMENTAL API, use at your own risk

    Constructors

    | Improve this Doc View Source

    Expression(String, String[])

    Creates a new Expression.

    Declaration
    public Expression(string sourceText, string[] variables)
    Parameters
    Type Name Description
    System.String sourceText

    Source text for the expression: e.g. ln(popularity)

    System.String[] variables

    Names of external variables referred to by the expression

    Properties

    | Improve this Doc View Source

    SourceText

    The original source text

    Declaration
    public string SourceText { get; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    Variables

    Named variables referred to by this expression

    Declaration
    public string[] Variables { get; }
    Property Value
    Type Description
    System.String[]

    Methods

    | Improve this Doc View Source

    Evaluate(Int32, FunctionValues[])

    Evaluates the expression for the given document.

    Declaration
    public abstract double Evaluate(int document, FunctionValues[] functionValues)
    Parameters
    Type Name Description
    System.Int32 document

    docId of the document to compute a value for

    FunctionValues[] functionValues

    FunctionValues for each element of Variables.

    Returns
    Type Description
    System.Double

    The computed value of the expression for the given document.

    Remarks

    Evaluates the expression for the given document.

    | Improve this Doc View Source

    GetRescorer(Bindings)

    Get a , to rescore first-pass hits using this expression.

    Declaration
    public virtual Rescorer GetRescorer(Bindings bindings)
    Parameters
    Type Name Description
    Bindings bindings
    Returns
    Type Description
    Rescorer
    | Improve this Doc View Source

    GetSortField(Bindings, Boolean)

    Get a sort field which can be used to rank documents by this expression.

    Declaration
    public virtual SortField GetSortField(Bindings bindings, bool reverse)
    Parameters
    Type Name Description
    Bindings bindings
    System.Boolean reverse
    Returns
    Type Description
    SortField
    Remarks

    Get a sort field which can be used to rank documents by this expression.

    | Improve this Doc View Source

    GetValueSource(Bindings)

    Get a value source which can compute the value of this expression in the context of the given bindings.

    Declaration
    public virtual ValueSource GetValueSource(Bindings bindings)
    Parameters
    Type Name Description
    Bindings bindings

    Bindings to use for external values in this expression

    Returns
    Type Description
    ValueSource

    A value source which will evaluate this expression when used

    Remarks

    Get a value source which can compute the value of this expression in the context of the given bindings.

    See Also

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