diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/Expression.java b/lucene/expressions/src/java/org/apache/lucene/expressions/Expression.java index c92e21b17e4..6340df7ad55 100644 --- a/lucene/expressions/src/java/org/apache/lucene/expressions/Expression.java +++ b/lucene/expressions/src/java/org/apache/lucene/expressions/Expression.java @@ -25,20 +25,38 @@ import org.apache.lucene.search.SortField; /** * Base class that computes the value of an expression for a document. *
- * Example usage: + * Example that sorts based on an expression: *
* // compile an expression: * Expression expr = JavascriptCompiler.compile("sqrt(_score) + ln(popularity)"); * * // SimpleBindings just maps variables to SortField instances - * SimpleBindings bindings = new SimpleBindings(); + * 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); + * searcher.search(query, 10, sort); + *+ *
+ * Example that modifies the scores produced by the query: + *
+ * // 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 query that matches based on body:contents but + * // scores using expr + * Query query = new FunctionScoreQuery( + * new TermQuery(new Term("body", "contents")), + * expr.getDoubleValuesSource(bindings)); + * searcher.search(query, 10); ** @see JavascriptCompiler#compile * @lucene.experimental