From 1cfa048643a821f0cd20c1a0fd912879c67aa81d Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 1 Mar 2017 17:20:08 +0100 Subject: [PATCH] Add a reference to FunctionScoreQuery to javadocs of Expression. --- .../apache/lucene/expressions/Expression.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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