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
    object
    Expression
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    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

    Expression(string, string[])

    Creates a new Expression.

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

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

    string[] variables

    Names of external variables referred to by the 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.

    See Also
    Compile(string)

    Properties

    SourceText

    The original source text

    Declaration
    public string SourceText { get; }
    Property Value
    Type Description
    string
    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.

    See Also
    Compile(string)

    Variables

    Named variables referred to by this expression

    Declaration
    public string[] Variables { get; }
    Property Value
    Type Description
    string[]
    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.

    See Also
    Compile(string)

    Methods

    Evaluate(int, FunctionValues[])

    Evaluates the expression for the given document.

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

    docId of the document to compute a value for

    FunctionValues[] functionValues

    Lucene.Net.Queries.Function.FunctionValues for each element of variables.

    Returns
    Type Description
    double

    The computed value of the expression for the given document.

    Remarks

    Evaluates the expression for the given document.

    See Also
    Compile(string)

    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
    Rescorer
    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.

    See Also
    Compile(string)

    GetSortField(Bindings, bool)

    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
    bool reverse
    Returns
    Type Description
    SortField
    Remarks

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

    See Also
    Compile(string)

    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)

    See Also

    Compile(string)
    Back to top Copyright © 2024 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.