Class Expression
Base class that computes the value of an expression for a document.
Inheritance
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);
Constructors
| Improve this Doc View SourceExpression(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.
|
System.String[] | variables | Names of external variables referred to by the expression |
Properties
| Improve this Doc View SourceSourceText
The original source text
Declaration
public string SourceText { get; }
Property Value
Type | Description |
---|---|
System.String |
Variables
Named variables referred to by this expression
Declaration
public string[] Variables { get; }
Property Value
Type | Description |
---|---|
System.String[] |
Methods
| Improve this Doc View SourceEvaluate(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 |
|
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.
GetRescorer(Bindings)
Get a
Declaration
public virtual Rescorer GetRescorer(Bindings bindings)
Parameters
Type | Name | Description |
---|---|---|
Bindings | bindings |
Returns
Type | Description |
---|---|
Rescorer |
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.
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.