Skip to content

Commit

Permalink
Moved FieldType to the bottom of the file
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Dec 11, 2023
1 parent c0c1125 commit 4b06655
Showing 1 changed file with 35 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,40 @@ private static SemanticTextFieldMapper toType(FieldMapper in) {
return (SemanticTextFieldMapper) in;
}

public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n), notInMultiFields(CONTENT_TYPE));

private final String modelId;

private SemanticTextFieldMapper(String simpleName, MappedFieldType mappedFieldType, String modelId, CopyTo copyTo) {
super(simpleName, mappedFieldType, MultiFields.empty(), copyTo);
this.modelId = modelId;
}

public String getModelId() {
return modelId;
}

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName()).init(this);
}

@Override
protected void parseCreateField(DocumentParserContext context) throws IOException {
// Just parses text - no indexing is performed
context.parser().textOrNull();
}

@Override
protected String contentType() {
return CONTENT_TYPE;
}

@Override
public SemanticTextFieldType fieldType() {
return (SemanticTextFieldType) super.fieldType();
}

public static class Builder extends FieldMapper.Builder {

private final Parameter<String> modelId = Parameter.stringParam("model_id", false, m -> toType(m).fieldType().modelId, null)
Expand Down Expand Up @@ -71,14 +105,11 @@ public SemanticTextFieldMapper build(MapperBuilderContext context) {
name(),
new SemanticTextFieldType(name(), modelId.getValue(), meta.getValue()),
modelId.getValue(),
copyTo,
this
copyTo
);
}
}

public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n), notInMultiFields(CONTENT_TYPE));

public static class SemanticTextFieldType extends SimpleMappedFieldType implements InferenceModelFieldType {

private final String modelId;
Expand Down Expand Up @@ -113,39 +144,4 @@ public IndexFieldData.Builder fielddataBuilder(FieldDataContext fieldDataContext
throw new IllegalArgumentException("[semantic_text] fields do not support sorting, scripting or aggregating");
}
}

private final String modelId;

private final Builder builder;

private SemanticTextFieldMapper(String simpleName, MappedFieldType mappedFieldType, String modelId, CopyTo copyTo, Builder builder) {
super(simpleName, mappedFieldType, MultiFields.empty(), copyTo);
this.builder = builder;
this.modelId = modelId;
}

public String getModelId() {
return modelId;
}

@Override
public FieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName()).init(this);
}

@Override
protected void parseCreateField(DocumentParserContext context) throws IOException {
// Just parses text - no indexing is performed
context.parser().textOrNull();
}

@Override
protected String contentType() {
return CONTENT_TYPE;
}

@Override
public SemanticTextFieldType fieldType() {
return (SemanticTextFieldType) super.fieldType();
}
}

0 comments on commit 4b06655

Please sign in to comment.