|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.expressions.Expression
public abstract class Expression
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", 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)
Field Summary | |
---|---|
String |
sourceText
The original source text |
String[] |
variables
Named variables referred to by this expression |
Constructor Summary | |
---|---|
protected |
Expression(String sourceText,
String[] variables)
Creates a new Expression . |
Method Summary | |
---|---|
abstract double |
evaluate(int document,
FunctionValues[] functionValues)
Evaluates the expression for the given document. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final String sourceText
public final String[] variables
Constructor Detail |
---|
protected Expression(String sourceText, String[] variables)
Expression
.
sourceText
- Source text for the expression: e.g. ln(popularity)
variables
- Names of external variables referred to by the expressionMethod Detail |
---|
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 expression
public SortField getSortField(Bindings bindings, boolean reverse)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |