-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Move FieldMapper#valueFetcher to MappedFieldType #62974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5b74dde
5b13f4c
0f750b9
d450600
1d4ec99
4cfc51d
3a7494a
ab26af5
477b48b
11c4fb1
adc8b9a
1d25eeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,7 +122,7 @@ protected List<Parameter<?>> getParameters() { | |
| @Override | ||
| public ScaledFloatFieldMapper build(BuilderContext context) { | ||
| ScaledFloatFieldType type = new ScaledFloatFieldType(buildFullName(context), indexed.getValue(), stored.getValue(), | ||
| hasDocValues.getValue(), meta.getValue(), scalingFactor.getValue()); | ||
| hasDocValues.getValue(), meta.getValue(), scalingFactor.getValue(), nullValue.getValue()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These telescoping constructors are getting too complicated now - one idea I have for a follow-up is to add a |
||
| return new ScaledFloatFieldMapper(name, type, multiFieldsBuilder.build(this, context), copyTo.build(), this); | ||
| } | ||
| } | ||
|
|
@@ -132,15 +132,17 @@ public ScaledFloatFieldMapper build(BuilderContext context) { | |
| public static final class ScaledFloatFieldType extends SimpleMappedFieldType { | ||
|
|
||
| private final double scalingFactor; | ||
| private final Double nullValue; | ||
|
|
||
| public ScaledFloatFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues, | ||
| Map<String, String> meta, double scalingFactor) { | ||
| Map<String, String> meta, double scalingFactor, Double nullValue) { | ||
| super(name, indexed, stored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta); | ||
| this.scalingFactor = scalingFactor; | ||
| this.nullValue = nullValue; | ||
| } | ||
|
|
||
| public ScaledFloatFieldType(String name, double scalingFactor) { | ||
| this(name, true, false, true, Collections.emptyMap(), scalingFactor); | ||
| this(name, true, false, true, Collections.emptyMap(), scalingFactor, null); | ||
| } | ||
|
|
||
| public double getScalingFactor() { | ||
|
|
@@ -204,6 +206,30 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S | |
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { | ||
| if (format != null) { | ||
| throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); | ||
| } | ||
| return new SourceValueFetcher(name(), mapperService, false) { | ||
| @Override | ||
| protected Double parseSourceValue(Object value) { | ||
| double doubleValue; | ||
| if (value.equals("")) { | ||
| if (nullValue == null) { | ||
| return null; | ||
| } | ||
| doubleValue = nullValue; | ||
| } else { | ||
| doubleValue = objectToDouble(value); | ||
| } | ||
|
|
||
| double scalingFactor = getScalingFactor(); | ||
| return Math.round(doubleValue * scalingFactor) / scalingFactor; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public Object valueForDisplay(Object value) { | ||
| if (value == null) { | ||
|
|
@@ -380,31 +406,6 @@ private static double objectToDouble(Object value) { | |
| return doubleValue; | ||
| } | ||
|
|
||
| @Override | ||
| public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { | ||
| if (format != null) { | ||
| throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); | ||
| } | ||
| return new SourceValueFetcher(name(), mapperService, parsesArrayValue()) { | ||
| @Override | ||
| protected Double parseSourceValue(Object value) { | ||
| double doubleValue; | ||
| if (value.equals("")) { | ||
| if (nullValue == null) { | ||
| return null; | ||
| } | ||
| doubleValue = nullValue; | ||
| } else { | ||
| doubleValue = objectToDouble(value); | ||
| } | ||
|
|
||
| double scalingFactor = fieldType().getScalingFactor(); | ||
| return Math.round(doubleValue * scalingFactor) / scalingFactor; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| private static class ScaledFloatIndexFieldData extends IndexNumericFieldData { | ||
|
|
||
| private final IndexNumericFieldData scaledFieldData; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ | |
| import org.apache.lucene.analysis.TokenStream; | ||
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; | ||
| import org.elasticsearch.index.analysis.NamedAnalyzer; | ||
| import org.elasticsearch.search.lookup.SearchLookup; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
|
|
@@ -79,6 +78,8 @@ public TokenCountFieldMapper build(BuilderContext context) { | |
| index.getValue(), | ||
| store.getValue(), | ||
| hasDocValues.getValue(), | ||
| false, | ||
| nullValue.getValue(), | ||
| meta.getValue()); | ||
| return new TokenCountFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo.build(), this); | ||
| } | ||
|
|
@@ -129,20 +130,6 @@ protected void parseCreateField(ParseContext context) throws IOException { | |
| ); | ||
| } | ||
|
|
||
| @Override | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this change, I think value parsing will always fail -- since it uses |
||
| public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { | ||
| if (format != null) { | ||
| throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] doesn't support formats."); | ||
| } | ||
|
|
||
| return new SourceValueFetcher(name(), mapperService, parsesArrayValue(), nullValue) { | ||
| @Override | ||
| protected String parseSourceValue(Object value) { | ||
| return value.toString(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Count position increments in a token stream. Package private for testing. | ||
| * @param analyzer analyzer to create token stream | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other change I noticed -- previously we always passed the result of
FieldMapper#parsesArrayValueinstead of hard-coding the booleans. Now there is nothing really tying this toparsesArrayValueand it could be easily overlooked. I wonder how we could make this more robust.An update: I opened #63354 with a small improvement.