Skip to content
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

Fix MatchOnlyTextFieldMapper Retaining a Reference to its Builder #77201

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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