Skip to content

Commit

Permalink
Encapsulate Mapper.Builder#name and make it private (elastic#105648)
Browse files Browse the repository at this point in the history
This is in preparation to make the field mutable,
which is needed in the context of elastic#103542
  • Loading branch information
felixbarny committed Feb 20, 2024
1 parent 0d0b319 commit 5920c91
Show file tree
Hide file tree
Showing 43 changed files with 111 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private static void setupPrefixTrees(GeoShapeFieldType ft) {

private GeoShapeFieldType buildFieldType(LegacyGeoShapeParser parser, MapperBuilderContext context) {
GeoShapeFieldType ft = new GeoShapeFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.get(),
orientation.get().value(),
parser,
Expand Down Expand Up @@ -353,7 +353,7 @@ private static int getLevels(int treeLevels, double precisionInMeters, int defau
public LegacyGeoShapeFieldMapper build(MapperBuilderContext context) {
LegacyGeoShapeParser parser = new LegacyGeoShapeParser();
GeoShapeFieldType ft = buildFieldType(parser, context);
return new LegacyGeoShapeFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
return new LegacyGeoShapeFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, parser, this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context) {
NamedAnalyzer indexAnalyzer = analyzers.getIndexAnalyzer();
TextSearchInfo tsi = new TextSearchInfo(Defaults.FIELD_TYPE, null, searchAnalyzer, searchQuoteAnalyzer);
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType(
context.buildFullName(name),
context.buildFullName(name()),
tsi,
indexAnalyzer,
context.isSourceSynthetic(),
Expand All @@ -140,7 +140,7 @@ private MatchOnlyTextFieldType buildFieldType(MapperBuilderContext context) {
public MatchOnlyTextFieldMapper build(MapperBuilderContext context) {
MatchOnlyTextFieldType tft = buildFieldType(context);
MultiFields multiFields = multiFieldsBuilder.build(this, context);
return new MatchOnlyTextFieldMapper(name, Defaults.FIELD_TYPE, tft, multiFields, copyTo, context.isSourceSynthetic(), this);
return new MatchOnlyTextFieldMapper(name(), Defaults.FIELD_TYPE, tft, multiFields, copyTo, context.isSourceSynthetic(), this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ protected Parameter<?>[] getParameters() {
@Override
public RankFeatureFieldMapper build(MapperBuilderContext context) {
return new RankFeatureFieldMapper(
name,
name(),
new RankFeatureFieldType(
context.buildFullName(name),
context.buildFullName(name()),
meta.getValue(),
positiveScoreImpact.getValue(),
nullValue.getValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ protected Parameter<?>[] getParameters() {
@Override
public RankFeaturesFieldMapper build(MapperBuilderContext context) {
return new RankFeaturesFieldMapper(
name,
new RankFeaturesFieldType(context.buildFullName(name), meta.getValue(), positiveScoreImpact.getValue()),
name(),
new RankFeaturesFieldType(context.buildFullName(name()), meta.getValue(), positiveScoreImpact.getValue()),
multiFieldsBuilder.build(this, context),
copyTo,
positiveScoreImpact.getValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected Parameter<?>[] getParameters() {
@Override
public ScaledFloatFieldMapper build(MapperBuilderContext context) {
ScaledFloatFieldType type = new ScaledFloatFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.getValue(),
stored.getValue(),
hasDocValues.getValue(),
Expand All @@ -196,7 +196,7 @@ public ScaledFloatFieldMapper build(MapperBuilderContext context) {
metric.getValue(),
indexMode
);
return new ScaledFloatFieldMapper(name, type, multiFieldsBuilder.build(this, context), copyTo, this);
return new ScaledFloatFieldMapper(name(), type, multiFieldsBuilder.build(this, context), copyTo, this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public SearchAsYouTypeFieldMapper build(MapperBuilderContext context) {
NamedAnalyzer searchAnalyzer = analyzers.getSearchAnalyzer();

SearchAsYouTypeFieldType ft = new SearchAsYouTypeFieldType(
context.buildFullName(name),
context.buildFullName(name()),
fieldType,
similarity.getValue(),
analyzers.getSearchAnalyzer(),
Expand All @@ -202,7 +202,7 @@ public SearchAsYouTypeFieldMapper build(MapperBuilderContext context) {
prefixft.setIndexOptions(fieldType.indexOptions());
prefixft.setOmitNorms(true);
prefixft.setStored(false);
final String fullName = context.buildFullName(name);
final String fullName = context.buildFullName(name());
// wrap the root field's index analyzer with shingles and edge ngrams
final Analyzer prefixIndexWrapper = SearchAsYouTypeAnalyzer.withShingleAndPrefix(
indexAnalyzer.analyzer(),
Expand All @@ -228,7 +228,7 @@ public SearchAsYouTypeFieldMapper build(MapperBuilderContext context) {
final int shingleSize = i + 2;
FieldType shingleft = new FieldType(fieldType);
shingleft.setStored(false);
String fieldName = getShingleFieldName(context.buildFullName(name), shingleSize);
String fieldName = getShingleFieldName(context.buildFullName(name()), shingleSize);
// wrap the root field's index, search, and search quote analyzers with shingles
final SearchAsYouTypeAnalyzer shingleIndexWrapper = SearchAsYouTypeAnalyzer.withShingle(
indexAnalyzer.analyzer(),
Expand Down Expand Up @@ -260,7 +260,7 @@ public SearchAsYouTypeFieldMapper build(MapperBuilderContext context) {
ft.setPrefixField(prefixFieldType);
ft.setShingleFields(shingleFieldTypes);
return new SearchAsYouTypeFieldMapper(
name,
name(),
ft,
copyTo,
indexAnalyzers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ protected Parameter<?>[] getParameters() {
@Override
public TokenCountFieldMapper build(MapperBuilderContext context) {
if (analyzer.getValue() == null) {
throw new MapperParsingException("Analyzer must be set for field [" + name + "] but wasn't.");
throw new MapperParsingException("Analyzer must be set for field [" + name() + "] but wasn't.");
}
MappedFieldType ft = new TokenCountFieldType(
context.buildFullName(name),
context.buildFullName(name()),
index.getValue(),
store.getValue(),
hasDocValues.getValue(),
nullValue.getValue(),
meta.getValue()
);
return new TokenCountFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo, this);
return new TokenCountFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ protected Parameter<?>[] getParameters() {

@Override
public ParentJoinFieldMapper build(MapperBuilderContext context) {
checkObjectOrNested(context, name);
checkObjectOrNested(context, name());
final Map<String, ParentIdFieldMapper> parentIdFields = new HashMap<>();
relations.get()
.stream()
.map(relation -> new ParentIdFieldMapper(name + "#" + relation.parent(), eagerGlobalOrdinals.get()))
.map(relation -> new ParentIdFieldMapper(name() + "#" + relation.parent(), eagerGlobalOrdinals.get()))
.forEach(mapper -> parentIdFields.put(mapper.name(), mapper));
Joiner joiner = new Joiner(name(), relations.get());
return new ParentJoinFieldMapper(
name,
new JoinFieldType(context.buildFullName(name), joiner, meta.get()),
name(),
new JoinFieldType(context.buildFullName(name()), joiner, meta.get()),
Collections.unmodifiableMap(parentIdFields),
eagerGlobalOrdinals.get(),
relations.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ protected Parameter<?>[] getParameters() {

@Override
public PercolatorFieldMapper build(MapperBuilderContext context) {
PercolatorFieldType fieldType = new PercolatorFieldType(context.buildFullName(name), meta.getValue());
PercolatorFieldType fieldType = new PercolatorFieldType(context.buildFullName(name()), meta.getValue());
// TODO should percolator even allow multifields?
MultiFields multiFields = multiFieldsBuilder.build(this, context);
context = context.createChildContext(name);
context = context.createChildContext(name());
KeywordFieldMapper extractedTermsField = createExtractQueryFieldBuilder(
EXTRACTED_TERMS_FIELD_NAME,
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public ICUCollationKeywordFieldMapper build(MapperBuilderContext context) {
final CollatorParams params = collatorParams();
final Collator collator = params.buildCollator();
CollationFieldType ft = new CollationFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.getValue(),
stored.getValue(),
hasDocValues.getValue(),
Expand All @@ -337,7 +337,7 @@ public ICUCollationKeywordFieldMapper build(MapperBuilderContext context) {
meta.getValue()
);
return new ICUCollationKeywordFieldMapper(
name,
name(),
buildFieldType(),
ft,
multiFieldsBuilder.build(this, context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private AnnotatedTextFieldType buildFieldType(FieldType fieldType, MapperBuilder
wrapAnalyzer(analyzers.getSearchQuoteAnalyzer())
);
return new AnnotatedTextFieldType(
context.buildFullName(name),
context.buildFullName(name()),
store.getValue(),
tsi,
context.isSourceSynthetic(),
Expand All @@ -139,12 +139,12 @@ public AnnotatedTextFieldMapper build(MapperBuilderContext context) {
if (analyzers.positionIncrementGap.isConfigured()) {
if (fieldType.indexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
throw new IllegalArgumentException(
"Cannot set position_increment_gap on field [" + name + "] without positions enabled"
"Cannot set position_increment_gap on field [" + name() + "] without positions enabled"
);
}
}
return new AnnotatedTextFieldMapper(
name,
name(),
fieldType,
buildFieldType(fieldType, context),
multiFieldsBuilder.build(this, context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ protected Parameter<?>[] getParameters() {
@Override
public Murmur3FieldMapper build(MapperBuilderContext context) {
return new Murmur3FieldMapper(
name,
new Murmur3FieldType(context.buildFullName(name), stored.getValue(), meta.getValue()),
name(),
new Murmur3FieldType(context.buildFullName(name()), stored.getValue(), meta.getValue()),
multiFieldsBuilder.build(this, context),
copyTo
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public Parameter<?>[] getParameters() {
@Override
public BinaryFieldMapper build(MapperBuilderContext context) {
return new BinaryFieldMapper(
name,
new BinaryFieldType(context.buildFullName(name), stored.getValue(), hasDocValues.getValue(), meta.getValue()),
name(),
new BinaryFieldType(context.buildFullName(name()), stored.getValue(), hasDocValues.getValue(), meta.getValue()),
multiFieldsBuilder.build(this, context),
copyTo,
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ protected Parameter<?>[] getParameters() {
@Override
public BooleanFieldMapper build(MapperBuilderContext context) {
MappedFieldType ft = new BooleanFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.getValue() && indexCreatedVersion.isLegacyIndexVersion() == false,
stored.getValue(),
docValues.getValue(),
nullValue.getValue(),
scriptValues(),
meta.getValue()
);
return new BooleanFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo, context.isSourceSynthetic(), this);
return new BooleanFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, context.isSourceSynthetic(), this);
}

private FieldValues<Boolean> scriptValues() {
Expand All @@ -133,7 +133,7 @@ private FieldValues<Boolean> scriptValues() {
BooleanFieldScript.Factory scriptFactory = scriptCompiler.compile(script.get(), BooleanFieldScript.CONTEXT);
return scriptFactory == null
? null
: (lookup, ctx, doc, consumer) -> scriptFactory.newFactory(name, script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> scriptFactory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public CompletionFieldMapper build(MapperBuilderContext context) {
new CompletionAnalyzer(this.searchAnalyzer.getValue(), preserveSeparators.getValue(), preservePosInc.getValue())
);

CompletionFieldType ft = new CompletionFieldType(context.buildFullName(name), completionAnalyzer, meta.getValue());
CompletionFieldType ft = new CompletionFieldType(context.buildFullName(name()), completionAnalyzer, meta.getValue());
ft.setContextMappings(contexts.getValue());
return new CompletionFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo, this);
return new CompletionFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, this);
}

private void checkCompletionContextsLimit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private FieldValues<Long> scriptValues() {
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(
name,
name(),
script.get().getParams(),
lookup,
buildFormatter(),
Expand Down Expand Up @@ -364,7 +364,7 @@ public DateFieldMapper build(MapperBuilderContext context) {
&& ignoreMalformed.isConfigured() == false) {
ignoreMalformed.setValue(false);
}
return new DateFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo, nullTimestamp, resolution, this);
return new DateFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, nullTimestamp, resolution, this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,23 @@ private FieldValues<GeoPoint> scriptValues() {
GeoPointFieldScript.Factory factory = scriptCompiler.compile(this.script.get(), GeoPointFieldScript.CONTEXT);
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(name, script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> factory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}

@Override
public FieldMapper build(MapperBuilderContext context) {
Parser<GeoPoint> geoParser = new GeoPointParser(
name,
name(),
(parser) -> GeoUtils.parseGeoPoint(parser, ignoreZValue.get().value()),
nullValue.get(),
ignoreZValue.get().value(),
ignoreMalformed.get().value(),
metric.get() != TimeSeriesParams.MetricType.POSITION
);
GeoPointFieldType ft = new GeoPointFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.get() && indexCreatedVersion.isLegacyIndexVersion() == false,
stored.get(),
hasDocValues.get(),
Expand All @@ -214,9 +214,9 @@ public FieldMapper build(MapperBuilderContext context) {
indexMode
);
if (this.script.get() == null) {
return new GeoPointFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo, geoParser, this);
return new GeoPointFieldMapper(name(), ft, multiFieldsBuilder.build(this, context), copyTo, geoParser, this);
}
return new GeoPointFieldMapper(name, ft, geoParser, this);
return new GeoPointFieldMapper(name(), ft, geoParser, this);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ public GeoShapeFieldMapper build(MapperBuilderContext context) {
);
GeoShapeParser geoShapeParser = new GeoShapeParser(geometryParser, orientation.get().value());
GeoShapeFieldType ft = new GeoShapeFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.get(),
orientation.get().value(),
geoShapeParser,
meta.get()
);
return new GeoShapeFieldMapper(
name,
name(),
ft,
multiFieldsBuilder.build(this, context),
copyTo,
new GeoShapeIndexer(orientation.get().value(), context.buildFullName(name)),
new GeoShapeIndexer(orientation.get().value(), context.buildFullName(name())),
geoShapeParser,
this
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private FieldValues<InetAddress> scriptValues() {
IpFieldScript.Factory factory = scriptCompiler.compile(this.script.get(), IpFieldScript.CONTEXT);
return factory == null
? null
: (lookup, ctx, doc, consumer) -> factory.newFactory(name, script.get().getParams(), lookup, OnScriptError.FAIL)
: (lookup, ctx, doc, consumer) -> factory.newFactory(name(), script.get().getParams(), lookup, OnScriptError.FAIL)
.newInstance(ctx)
.runForDoc(doc, consumer);
}
Expand All @@ -170,9 +170,9 @@ public IpFieldMapper build(MapperBuilderContext context) {
dimension.setValue(true);
}
return new IpFieldMapper(
name,
name(),
new IpFieldType(
context.buildFullName(name),
context.buildFullName(name()),
indexed.getValue() && indexCreatedVersion.isLegacyIndexVersion() == false,
stored.getValue(),
hasDocValues.getValue(),
Expand Down
Loading

0 comments on commit 5920c91

Please sign in to comment.