|
@@ -8,12 +8,11 @@
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
import org.apache.lucene.search.Query;
|
|
|
-import org.apache.lucene.util.SetOnce;
|
|
|
-import org.elasticsearch.core.CheckedConsumer;
|
|
|
import org.elasticsearch.common.Explicit;
|
|
|
import org.elasticsearch.common.geo.GeoFormatterFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.support.MapXContentParser;
|
|
|
+import org.elasticsearch.core.CheckedConsumer;
|
|
|
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
|
|
import org.elasticsearch.index.query.SearchExecutionContext;
|
|
|
|
|
@@ -65,12 +64,10 @@ public abstract class AbstractGeometryFieldMapper<T> extends FieldMapper {
|
|
|
public abstract static class AbstractGeometryFieldType<T> extends MappedFieldType {
|
|
|
|
|
|
protected final Parser<T> geometryParser;
|
|
|
- protected final boolean parsesArrayValue;
|
|
|
|
|
|
protected AbstractGeometryFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues,
|
|
|
- boolean parsesArrayValue, Parser<T> geometryParser, Map<String, String> meta) {
|
|
|
+ Parser<T> geometryParser, Map<String, String> meta) {
|
|
|
super(name, indexed, stored, hasDocValues, TextSearchInfo.NONE, meta);
|
|
|
- this.parsesArrayValue = parsesArrayValue;
|
|
|
this.geometryParser = geometryParser;
|
|
|
}
|
|
|
|
|
@@ -81,32 +78,21 @@ public abstract class AbstractGeometryFieldMapper<T> extends FieldMapper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets the formatter. If the method return null, then the format is unsupported and an error is thrown.
|
|
|
+ * Gets the formatter by name.
|
|
|
*/
|
|
|
protected abstract Function<T, Object> getFormatter(String format);
|
|
|
|
|
|
@Override
|
|
|
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
|
|
|
Function<T, Object> formatter = getFormatter(format != null ? format : GeoFormatterFactory.GEOJSON);
|
|
|
- if (parsesArrayValue) {
|
|
|
- return new ArraySourceValueFetcher(name(), context) {
|
|
|
- @Override
|
|
|
- protected Object parseSourceValue(Object value) {
|
|
|
- List<Object> values = new ArrayList<>();
|
|
|
- geometryParser.fetchFromSource(value, values::add, formatter);
|
|
|
- return values;
|
|
|
- }
|
|
|
- };
|
|
|
- } else {
|
|
|
- return new SourceValueFetcher(name(), context) {
|
|
|
- @Override
|
|
|
- protected Object parseSourceValue(Object value) {
|
|
|
- SetOnce<Object> holder = new SetOnce<>();
|
|
|
- geometryParser.fetchFromSource(value, holder::set, formatter);
|
|
|
- return holder.get();
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
+ return new ArraySourceValueFetcher(name(), context) {
|
|
|
+ @Override
|
|
|
+ protected Object parseSourceValue(Object value) {
|
|
|
+ List<Object> values = new ArrayList<>();
|
|
|
+ geometryParser.fetchFromSource(value, values::add, formatter);
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -187,4 +173,9 @@ public abstract class AbstractGeometryFieldMapper<T> extends FieldMapper {
|
|
|
public boolean ignoreZValue() {
|
|
|
return ignoreZValue.value();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public final boolean parsesArrayValue() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|