public abstract class SearchScript extends java.lang.Object implements ScorerAware, ExecutableScript
SearchScript works as follows:
SearchScript.Factory using ScriptService.compile(Script, ScriptContext)SearchScript.LeafFactory for a an index using SearchScript.Factory.newFactory(Map, SearchLookup)SearchScript for a Lucene segment using SearchScript.LeafFactory.newInstance(LeafReaderContext)setDocument(int) to indicate which document in the segment the script should be run for nextrun methods: run(), runAsDouble(), or runAsLong()| Modifier and Type | Class and Description |
|---|---|
static interface |
SearchScript.Factory
A factory to construct stateful
SearchScript factories for a specific index. |
static interface |
SearchScript.LeafFactory
A factory to construct
SearchScript instances. |
| Modifier and Type | Field and Description |
|---|---|
static ScriptContext<SearchScript.Factory> |
AGGS_CONTEXT |
static ScriptContext<SearchScript.Factory> |
CONTEXT
The context used to compile
SearchScript factories. |
INGEST_CONTEXT, UPDATE_CONTEXT| Constructor and Description |
|---|
SearchScript(java.util.Map<java.lang.String,java.lang.Object> params,
SearchLookup lookup,
org.apache.lucene.index.LeafReaderContext leafContext) |
| Modifier and Type | Method and Description |
|---|---|
LeafDocLookup |
getDoc()
The doc lookup for the Lucene segment this script was created for.
|
protected org.apache.lucene.index.LeafReaderContext |
getLeafContext()
The leaf context for the Lucene segment this script was created for.
|
protected LeafSearchLookup |
getLeafLookup()
The leaf lookup for the Lucene segment this script was created for.
|
java.util.Map<java.lang.String,java.lang.Object> |
getParams()
Return the parameters for this script.
|
double |
getScore()
Return the score of the current document.
|
java.lang.Object |
run()
Executes the script.
|
abstract double |
runAsDouble()
Return the result as a double.
|
long |
runAsLong()
Return the result as a long.
|
void |
setDocument(int docid)
Set the current document to run the script on next.
|
void |
setNextAggregationValue(java.lang.Object value)
Sets per-document aggregation
_value. |
void |
setNextVar(java.lang.String field,
java.lang.Object value)
Sets a runtime script parameter.
|
void |
setScorer(org.apache.lucene.search.Scorer scorer) |
public static final ScriptContext<SearchScript.Factory> CONTEXT
SearchScript factories.public static final ScriptContext<SearchScript.Factory> AGGS_CONTEXT
public SearchScript(java.util.Map<java.lang.String,java.lang.Object> params,
SearchLookup lookup,
org.apache.lucene.index.LeafReaderContext leafContext)
public java.util.Map<java.lang.String,java.lang.Object> getParams()
protected final LeafSearchLookup getLeafLookup()
protected final org.apache.lucene.index.LeafReaderContext getLeafContext()
public final LeafDocLookup getDoc()
public void setDocument(int docid)
public void setScorer(org.apache.lucene.search.Scorer scorer)
setScorer in interface ScorerAwarepublic double getScore()
public void setNextAggregationValue(java.lang.Object value)
_value.
The default implementation just calls setNextVar("_value", value) but
some engines might want to handle this differently for better performance.
value - per-document value, typically a String, Long, or Doublepublic void setNextVar(java.lang.String field,
java.lang.Object value)
ExecutableScriptNote that this method may be slow, involving put() and get() calls to a hashmap or similar.
setNextVar in interface ExecutableScriptfield - parameter namevalue - parameter valuepublic long runAsLong()
public java.lang.Object run()
ExecutableScriptrun in interface ExecutableScriptpublic abstract double runAsDouble()