expose simplified field methods for custom scripts

also, add respective iter methods to the script values to be used in custom scripts
This commit is contained in:
Shay Banon 2013-08-14 18:21:09 +02:00
parent 3ac3c7d12c
commit 594e03b695
2 changed files with 50 additions and 0 deletions

View File

@ -98,6 +98,18 @@ public abstract class ScriptDocValues {
return !values.hasValue(docId);
}
public BytesValues getInternalValues() {
return this.values;
}
public Iter getBytesIter() {
return values.getIter(docId);
}
public BytesRef getBytesValue() {
return values.getValue(docId);
}
public String getValue() {
final BytesRef value = values.getValue(docId);
if (value != null) {
@ -137,11 +149,19 @@ public abstract class ScriptDocValues {
this.list = new SlicedLongList(values.isMultiValued() ? 10 : 1);
}
public LongValues getInternalValues() {
return this.values;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public LongValues.Iter getIter() {
return values.getIter(docId);
}
public long getValue() {
return values.getValue(docId);
}
@ -178,11 +198,19 @@ public abstract class ScriptDocValues {
}
public DoubleValues getInternalValues() {
return this.values;
}
@Override
public boolean isEmpty() {
return !values.hasValue(docId);
}
public DoubleValues.Iter getIter() {
return values.getIter(docId);
}
public double getValue() {
return values.getValue(docId);
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.script;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.Scorer;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.search.lookup.DocLookup;
import org.elasticsearch.search.lookup.FieldsLookup;
import org.elasticsearch.search.lookup.SearchLookup;
@ -59,6 +60,27 @@ public abstract class AbstractSearchScript extends AbstractExecutableScript impl
return lookup.doc();
}
/**
* Returns field data strings access for the provided field.
*/
protected ScriptDocValues.Strings docFieldStrings(String field) {
return (ScriptDocValues.Strings) doc().get(field);
}
/**
* Returns field data double (floating point) access for the provided field.
*/
protected ScriptDocValues.Doubles docFieldDoubles(String field) {
return (ScriptDocValues.Doubles) doc().get(field);
}
/**
* Returns field data long (integers) access for the provided field.
*/
protected ScriptDocValues.Longs docFieldLongs(String field) {
return (ScriptDocValues.Longs) doc().get(field);
}
/**
* Allows to access the actual source (loaded and parsed).
*/