Skip to content

Commit

Permalink
Fix MatchOnlyTextFieldMapper Retaining a Reference to its Builder
Browse files Browse the repository at this point in the history
Just like elastic#77131 but for the `MatchOnlyTextFieldMapper`. Also, cleaned up a few
other minor things in it to make the constructor code for this class easier to follow.
  • Loading branch information
original-brownbear committed Sep 2, 2021
1 parent 0305f95 commit 3f6a279
Showing 1 changed file with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,10 +71,6 @@ public static class Defaults {

}

private static Builder builder(FieldMapper in) {
return ((MatchOnlyTextFieldMapper) in).builder;
}

public static class Builder extends FieldMapper.Builder {

private final Version indexCreatedVersion;
Expand All @@ -91,37 +86,30 @@ public Builder(String name, IndexAnalyzers indexAnalyzers) {
public Builder(String name, Version indexCreatedVersion, IndexAnalyzers indexAnalyzers) {
super(name);
this.indexCreatedVersion = indexCreatedVersion;
this.analyzers = new TextParams.Analyzers(indexAnalyzers, m -> builder(m).analyzers);
}

public Builder addMultiField(FieldMapper.Builder builder) {
this.multiFieldsBuilder.add(builder);
return this;
this.analyzers = new TextParams.Analyzers(indexAnalyzers, m -> ((MatchOnlyTextFieldMapper) m).analyzers);
}

@Override
protected List<Parameter<?>> getParameters() {
return Arrays.asList(meta);
return List.of(meta);
}

private MatchOnlyTextFieldType buildFieldType(FieldType fieldType, ContentPath contentPath) {
private MatchOnlyTextFieldType buildFieldType(ContentPath contentPath) {
NamedAnalyzer searchAnalyzer = analyzers.getSearchAnalyzer();
NamedAnalyzer searchQuoteAnalyzer = analyzers.getSearchQuoteAnalyzer();
NamedAnalyzer indexAnalyzer = analyzers.getIndexAnalyzer();
TextSearchInfo tsi = new TextSearchInfo(fieldType, null, searchAnalyzer, searchQuoteAnalyzer);
MatchOnlyTextFieldType ft = new MatchOnlyTextFieldType(buildFullName(contentPath), tsi, indexAnalyzer, meta.getValue());
return ft;
TextSearchInfo tsi = new TextSearchInfo(Defaults.FIELD_TYPE, null, searchAnalyzer, searchQuoteAnalyzer);
return new MatchOnlyTextFieldType(buildFullName(contentPath), tsi, indexAnalyzer, meta.getValue());
}

@Override
public MatchOnlyTextFieldMapper build(ContentPath contentPath) {
MatchOnlyTextFieldType tft = buildFieldType(Defaults.FIELD_TYPE, contentPath);
MatchOnlyTextFieldType tft = buildFieldType(contentPath);
MultiFields multiFields = multiFieldsBuilder.build(this, contentPath);
return new MatchOnlyTextFieldMapper(
name,
Defaults.FIELD_TYPE,
tft,
analyzers.getIndexAnalyzer(),
multiFields,
copyTo.build(),
this
Expand All @@ -142,19 +130,6 @@ public MatchOnlyTextFieldType(String name, TextSearchInfo tsi, Analyzer indexAna
this.textFieldType = new TextFieldType(name);
}

public MatchOnlyTextFieldType(String name, boolean stored, Map<String, String> meta) {
super(
name,
true,
stored,
false,
new TextSearchInfo(Defaults.FIELD_TYPE, null, Lucene.STANDARD_ANALYZER, Lucene.STANDARD_ANALYZER),
meta
);
this.indexAnalyzer = Lucene.STANDARD_ANALYZER;
this.textFieldType = new TextFieldType(name);
}

public MatchOnlyTextFieldType(String name) {
this(
name,
Expand Down Expand Up @@ -292,28 +267,29 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S

}

private final Builder builder;
private final Version indexCreatedVersion;
private final TextParams.Analyzers analyzers;
private final FieldType fieldType;

private MatchOnlyTextFieldMapper(
String simpleName,
FieldType fieldType,
MatchOnlyTextFieldType mappedFieldType,
NamedAnalyzer indexAnalyzer,
MultiFields multiFields,
CopyTo copyTo,
Builder builder
) {
super(simpleName, mappedFieldType, indexAnalyzer, multiFields, copyTo);
super(simpleName, mappedFieldType, builder.analyzers.getIndexAnalyzer(), multiFields, copyTo);
assert mappedFieldType.getTextSearchInfo().isTokenized();
assert mappedFieldType.hasDocValues() == false;
this.fieldType = fieldType;
this.builder = builder;
this.indexCreatedVersion = builder.indexCreatedVersion;
this.analyzers = builder.analyzers;
}

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), builder.indexCreatedVersion, builder.analyzers.indexAnalyzers).init(this);
return new Builder(simpleName(), indexCreatedVersion, analyzers.indexAnalyzers).init(this);
}

@Override
Expand Down

0 comments on commit 3f6a279

Please sign in to comment.