Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit faaae0e

Browse files
committedApr 4, 2024·
Refactor code
Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
1 parent 57c62bd commit faaae0e

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed
 

‎server/src/main/java/org/opensearch/index/mapper/DerivedFieldMapper.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ public DerivedFieldMapper build(BuilderContext context) {
7272
name
7373
);
7474
DerivedFieldType ft = new DerivedFieldType(
75-
buildFullName(context),
76-
type.getValue(),
77-
script.getValue(),
75+
new DerivedField(buildFullName(context), type.getValue(), script.getValue()),
7876
fieldMapper,
7977
fieldFunction
8078
);

‎server/src/main/java/org/opensearch/index/mapper/DerivedFieldType.java

+9-20
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.opensearch.index.query.DerivedFieldQuery;
2424
import org.opensearch.index.query.QueryShardContext;
2525
import org.opensearch.script.DerivedFieldScript;
26-
import org.opensearch.script.Script;
2726
import org.opensearch.search.lookup.SearchLookup;
2827

2928
import java.io.IOException;
@@ -40,40 +39,30 @@
4039
*/
4140
@PublicApi(since = "2.14.0")
4241
public final class DerivedFieldType extends MappedFieldType {
43-
private final String type;
4442

45-
private final Script script;
43+
private final DerivedField derivedField;
4644

4745
FieldMapper typeFieldMapper;
4846

4947
final Function<Object, IndexableField> indexableFieldGenerator;
5048

5149
public DerivedFieldType(
52-
String name,
53-
String type,
54-
Script script,
50+
DerivedField derivedField,
5551
boolean isIndexed,
5652
boolean isStored,
5753
boolean hasDocValues,
5854
Map<String, String> meta,
5955
FieldMapper typeFieldMapper,
6056
Function<Object, IndexableField> fieldFunction
6157
) {
62-
super(name, isIndexed, isStored, hasDocValues, typeFieldMapper.fieldType().getTextSearchInfo(), meta);
63-
this.type = type;
64-
this.script = script;
58+
super(derivedField.getName(), isIndexed, isStored, hasDocValues, typeFieldMapper.fieldType().getTextSearchInfo(), meta);
59+
this.derivedField = derivedField;
6560
this.typeFieldMapper = typeFieldMapper;
6661
this.indexableFieldGenerator = fieldFunction;
6762
}
6863

69-
public DerivedFieldType(
70-
String name,
71-
String type,
72-
Script script,
73-
FieldMapper typeFieldMapper,
74-
Function<Object, IndexableField> fieldFunction
75-
) {
76-
this(name, type, script, false, false, false, Collections.emptyMap(), typeFieldMapper, fieldFunction);
64+
public DerivedFieldType(DerivedField derivedField, FieldMapper typeFieldMapper, Function<Object, IndexableField> fieldFunction) {
65+
this(derivedField, false, false, false, Collections.emptyMap(), typeFieldMapper, fieldFunction);
7766
}
7867

7968
@Override
@@ -82,7 +71,7 @@ public String typeName() {
8271
}
8372

8473
public String getType() {
85-
return type;
74+
return derivedField.getType();
8675
}
8776

8877
public NamedAnalyzer getIndexAnalyzer() {
@@ -280,7 +269,7 @@ private DerivedFieldScript.LeafFactory getDerivedFieldLeafFactory(QueryShardCont
280269
+ "]"
281270
);
282271
}
283-
DerivedFieldScript.Factory factory = context.compile(script, DerivedFieldScript.CONTEXT);
284-
return factory.newFactory(script.getParams(), context.lookup());
272+
DerivedFieldScript.Factory factory = context.compile(derivedField.getScript(), DerivedFieldScript.CONTEXT);
273+
return factory.newFactory(derivedField.getScript().getParams(), context.lookup());
285274
}
286275
}

‎server/src/test/java/org/opensearch/index/mapper/DerivedFieldTypeTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ private DerivedFieldType createDerivedFieldType(String type) {
2828
Mapper.BuilderContext context = mock(Mapper.BuilderContext.class);
2929
when(context.path()).thenReturn(new ContentPath());
3030
return new DerivedFieldType(
31-
type + " _derived_field",
32-
type,
33-
new Script(""),
31+
new DerivedField(type + " _derived_field", type, new Script("")),
3432
DerivedFieldSupportedTypes.getFieldMapperFromType(type, type + "_derived_field", context),
3533
DerivedFieldSupportedTypes.getIndexableFieldGeneratorType(type, type + "_derived_field")
3634
);

0 commit comments

Comments
 (0)
Please sign in to comment.