Skip to content

Apache Lucene open-source search software

LUCENE-5207: javadocs

Robert Muirc3229f37b077
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/SimpleBindings.java b/lucene/expressions/src/java/org/apache/lucene/expressions/SimpleBindings.java
index 7fede15e3a7..64f811beff7 100644
--- a/lucene/expressions/src/java/org/apache/lucene/expressions/SimpleBindings.java
+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/SimpleBindings.java
@@ -35,7 +35,21 @@ import org.apache.lucene.search.SortField;
/**
* Simple class that binds expression variable names to {@link SortField}s
* or other {@link Expression}s.
- *
+ * <p>
+ * Example usage:
+ * <pre class="prettyprint">
+ * SimpleBindings bindings = new SimpleBindings();
+ * // document's text relevance score
+ * bindings.add(new SortField("_score", SortField.Type.SCORE));
+ * // integer NumericDocValues field (or from FieldCache)
+ * bindings.add(new SortField("popularity", SortField.Type.INT));
+ * // another expression
+ * bindings.add("recency", myRecencyExpression);
+ *
+ * // create a sort field in reverse order
+ * Sort sort = new Sort(expr.getSortField(bindings, true));
+ * </pre>
+ *
* @lucene.experimental
*/
public final class SimpleBindings extends Bindings {
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java
index c8244ca4324..7d233fe8f9b 100644
--- a/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java
+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java
@@ -61,7 +61,21 @@ import org.objectweb.asm.commons.GeneratorAdapter;
* </pre>
* <p>
* See the {@link org.apache.lucene.expressions.js package documentation} for
- * the supported syntax and functions.
+ * the supported syntax and default functions.
+ * <p>
+ * You can compile with an alternate set of functions via {@link #compile(String, Map, ClassLoader)}.
+ * For example:
+ * <pre class="prettyprint">
+ * Map&lt;String,Method&gt; functions = new HashMap&lt;&gt;();
+ * // add all the default functions
+ * functions.putAll(JavascriptCompiler.DEFAULT_FUNCTIONS);
+ * // add cbrt()
+ * functions.put("cbrt", Math.class.getMethod("cbrt", double.class));
+ * // call compile with customized function map
+ * Expression foo = JavascriptCompiler.compile("cbrt(score)+ln(popularity)",
+ * functions,
+ * getClass().getClassLoader());
+ * </pre>
*
* @lucene.experimental
*/
@@ -122,7 +136,8 @@ public class JavascriptCompiler {
/**
* Compiles the given expression with the supplied custom functions.
* <p>
- * Functions must return {@code double} and can take from zero to 256 {@code double} parameters.
+ * Functions must be {@code public static}, return {@code double} and
+ * can take from zero to 256 {@code double} parameters.
*
* @param sourceText The expression to compile
* @param functions map of String names to functions