You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2017/03/01 16:21:32 UTC

[2/2] lucene-solr:branch_6x: Add a reference to FunctionScoreQuery to javadocs of Expression.

Add a reference to FunctionScoreQuery to javadocs of Expression.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0b4ccab6
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0b4ccab6
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0b4ccab6

Branch: refs/heads/branch_6x
Commit: 0b4ccab6d30c0bcbd7211746c622428785c52feb
Parents: a315897
Author: Adrien Grand <jp...@gmail.com>
Authored: Wed Mar 1 17:20:08 2017 +0100
Committer: Adrien Grand <jp...@gmail.com>
Committed: Wed Mar 1 17:21:05 2017 +0100

----------------------------------------------------------------------
 .../apache/lucene/expressions/Expression.java   | 24 +++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0b4ccab6/lucene/expressions/src/java/org/apache/lucene/expressions/Expression.java
----------------------------------------------------------------------
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 c92e21b..6340df7 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.
  * <p>
- * Example usage:
+ * Example that sorts based on an expression:
  * <pre class="prettyprint">
  *   // 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);
+ * </pre>
+ * <p>
+ * Example that modifies the scores produced by the query:
+ * <pre class="prettyprint">
+ *   // 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);
  * </pre>
  * @see JavascriptCompiler#compile
  * @lucene.experimental