public abstract class Expression extends Object
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", SortField.Type.SCORE)); bindings.add(new SortField("popularity", SortField.Type.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);
JavascriptCompiler.compile(java.lang.String)
Modifier and Type | Field and Description |
---|---|
String |
sourceText
The original source text
|
String[] |
variables
Named variables referred to by this expression
|
Modifier | Constructor and Description |
---|---|
protected |
Expression(String sourceText,
String[] variables)
Creates a new
Expression . |
Modifier and Type | Method and Description |
---|---|
abstract double |
evaluate(int document,
FunctionValues[] functionValues)
Evaluates the expression for the given document.
|
Rescorer |
getRescorer(Bindings bindings)
Get a
Rescorer , to rescore first-pass hits
using this expression. |
SortField |
getSortField(Bindings bindings,
boolean reverse)
Get a sort field which can be used to rank documents by this expression.
|
ValueSource |
getValueSource(Bindings bindings)
Get a value source which can compute the value of this expression in the context of the given bindings.
|
public final String sourceText
public final String[] variables
public abstract double evaluate(int document, FunctionValues[] functionValues)
document
- docId
of the document to compute a value forfunctionValues
- FunctionValues
for each element of variables
.public ValueSource getValueSource(Bindings bindings)
bindings
- Bindings to use for external values in this expressionpublic SortField getSortField(Bindings bindings, boolean reverse)
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.