Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class Expression

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

    Inheritance
    System.Object
    Expression
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Lucene.Net.Expressions
    Assembly: Lucene.Net.Expressions.dll
    Syntax
    public abstract class Expression
    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);
    Note

    This API is experimental and might change in incompatible ways in the next release.

    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

    Lucene.Net.Queries.Function.FunctionValues[] functionValues

    Lucene.Net.Queries.Function.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 Lucene.Net.Search.Rescorer, to rescore first-pass hits using this expression.

    Declaration
    public virtual Rescorer GetRescorer(Bindings bindings)
    Parameters
    Type Name Description
    Bindings bindings
    Returns
    Type Description
    Lucene.Net.Search.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
    Lucene.Net.Search.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
    Lucene.Net.Queries.Function.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 © 2021 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.