Class Expression
Base class that computes the value of an expression for a document.
Inherited Members
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.
|
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
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
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
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 |
|
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
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
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
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.