Skip to content

Commit ac82036

Browse files
committed
Add more java doc.
Signed-off-by: Bo Zhang <[email protected]>
1 parent 690c82a commit ac82036

17 files changed

+260
-235
lines changed

src/main/java/org/opensearch/neuralsearch/constants/FieldConstants.java

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package org.opensearch.neuralsearch.constants;
6+
7+
/**
8+
* Constants related to the index mapping.
9+
*/
10+
public class MappingConstants {
11+
/**
12+
* Name for the field type. In index mapping we use this key to define the field type.
13+
*/
14+
public static final String TYPE = "type";
15+
}

src/main/java/org/opensearch/neuralsearch/constants/SemanticFieldConstants.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,30 @@
44
*/
55
package org.opensearch.neuralsearch.constants;
66

7+
/**
8+
* Constants for semantic field
9+
*/
710
public class SemanticFieldConstants {
11+
/**
12+
* Name of the model id parameter. We use this key to define the id of the ML model that we will use for the
13+
* semantic field.
14+
*/
815
public static final String MODEL_ID = "model_id";
16+
17+
/**
18+
* Name of the search model id parameter. We use this key to define the id of the ML model that we will use to
19+
* inference the query text during the search. If this parameter is not defined we will use the model_id instead.
20+
*/
921
public static final String SEARCH_MODEL_ID = "search_model_id";
22+
23+
/**
24+
* Name of the raw field type parameter. We use this key to define the field type for the raw data. It will control
25+
* how to store and query the raw data.
26+
*/
1027
public static final String RAW_FIELD_TYPE = "raw_field_type";
28+
29+
/**
30+
* Name of the raw field type parameter. We use this key to define a custom field name for the semantic info.
31+
*/
1132
public static final String SEMANTIC_INFO_FIELD_NAME = "semantic_info_field_name";
1233
}

src/main/java/org/opensearch/neuralsearch/mapper/SemanticFieldMapper.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
import org.opensearch.index.mapper.TextFieldMapper;
1919
import org.opensearch.index.mapper.TokenCountFieldMapper;
2020
import org.opensearch.index.mapper.WildcardFieldMapper;
21-
import org.opensearch.neuralsearch.constants.FieldConstants;
22-
import org.opensearch.neuralsearch.mapper.semanticFieldTypes.SemanticFieldTypeFactory;
21+
import org.opensearch.neuralsearch.constants.MappingConstants;
22+
import org.opensearch.neuralsearch.mapper.semanticfieldtypes.SemanticFieldTypeFactory;
2323

2424
import java.io.IOException;
2525
import java.util.HashMap;
2626
import java.util.List;
2727
import java.util.Map;
28+
import java.util.Set;
2829

2930
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.MODEL_ID;
3031
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.RAW_FIELD_TYPE;
@@ -161,7 +162,7 @@ public SemanticFieldMapper build(BuilderContext context) {
161162

162163
public static class TypeParser implements Mapper.TypeParser {
163164

164-
private final static List<String> SUPPORTED_RAW_FIELD_TYPE = List.of(
165+
private final static Set<String> SUPPORTED_RAW_FIELD_TYPE = Set.of(
165166
TextFieldMapper.CONTENT_TYPE,
166167
KeywordFieldMapper.CONTENT_TYPE,
167168
MatchOnlyTextFieldMapper.CONTENT_TYPE,
@@ -215,15 +216,15 @@ private Map<String, Object> extractSemanticConfig(Map<String, Object> node, List
215216
node.remove(parameter.name);
216217
}
217218
}
218-
semanticConfig.put(FieldConstants.TYPE, SemanticFieldMapper.CONTENT_TYPE);
219-
node.put(FieldConstants.TYPE, rawFieldType);
219+
semanticConfig.put(MappingConstants.TYPE, SemanticFieldMapper.CONTENT_TYPE);
220+
node.put(MappingConstants.TYPE, rawFieldType);
220221
return semanticConfig;
221222
}
222223
}
223224

224225
@Override
225226
protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
226-
builder.field(FieldConstants.TYPE, contentType());
227+
builder.field(MappingConstants.TYPE, contentType());
227228

228229
// semantic parameters
229230
final List<Parameter<?>> parameters = getMergeBuilder().getParameters();

src/main/java/org/opensearch/neuralsearch/mapper/semanticFieldTypes/SemanticFieldType.java renamed to src/main/java/org/opensearch/neuralsearch/mapper/semanticfieldtypes/SemanticFieldType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package org.opensearch.neuralsearch.mapper.semanticFieldTypes;
5+
package org.opensearch.neuralsearch.mapper.semanticfieldtypes;
66

77
import lombok.Getter;
88
import lombok.NonNull;
@@ -19,6 +19,9 @@
1919
import java.time.ZoneId;
2020
import java.util.function.Supplier;
2121

22+
/**
23+
* A semantic field type that delegate the work to a mapped field type.
24+
*/
2225
public class SemanticFieldType extends MappedFieldType {
2326
@Getter
2427
private SemanticFieldTypeParameters semanticFieldTypeParameters;

src/main/java/org/opensearch/neuralsearch/mapper/semanticFieldTypes/SemanticFieldTypeFactory.java renamed to src/main/java/org/opensearch/neuralsearch/mapper/semanticfieldtypes/SemanticFieldTypeFactory.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package org.opensearch.neuralsearch.mapper.semanticFieldTypes;
5+
package org.opensearch.neuralsearch.mapper.semanticfieldtypes;
66

77
import lombok.NoArgsConstructor;
88
import lombok.NonNull;
@@ -18,17 +18,27 @@
1818
import org.opensearch.index.mapper.WildcardFieldMapper;
1919
import org.opensearch.neuralsearch.mapper.SemanticFieldMapper;
2020

21-
import java.util.List;
21+
import java.util.Set;
2222

23+
/**
24+
* A factory to create the semantic field type based on the raw field type.
25+
*/
2326
@NoArgsConstructor
2427
public class SemanticFieldTypeFactory {
25-
private static final List<String> STRING_FIELD_TYPES = List.of(
28+
private static final Set<String> STRING_FIELD_TYPES = Set.of(
2629
TextFieldMapper.CONTENT_TYPE,
2730
MatchOnlyTextFieldMapper.CONTENT_TYPE,
2831
KeywordFieldMapper.CONTENT_TYPE,
2932
WildcardFieldMapper.CONTENT_TYPE
3033
);
3134

35+
/**
36+
* Create the semantic field type based on the raw field type.
37+
* @param delegateMapper delegate field mapper
38+
* @param rawFieldType field type for the raw data
39+
* @param builder semantic field mapper builder
40+
* @return semantic field type
41+
*/
3242
public MappedFieldType createSemanticFieldType(
3343
@NonNull final ParametrizedFieldMapper delegateMapper,
3444
@NonNull final String rawFieldType,
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package org.opensearch.neuralsearch.mapper.semanticFieldTypes;
5+
package org.opensearch.neuralsearch.mapper.semanticfieldtypes;
66

77
import lombok.Getter;
88
import org.opensearch.neuralsearch.mapper.SemanticFieldMapper;
99

10+
/**
11+
* An object to hold all the parameters we can have in a semantic field type.
12+
*/
1013
@Getter
1114
public class SemanticFieldTypeParameters {
1215
private final String modelId;
1316
private final String searchModelId;
1417
private final String semanticInfoFieldName;
1518
private final String rawFieldType;
1619

17-
SemanticFieldTypeParameters(SemanticFieldMapper.Builder builder) {
20+
public SemanticFieldTypeParameters(SemanticFieldMapper.Builder builder) {
1821
modelId = builder.getModelId().getValue();
1922
searchModelId = builder.getSearchModelId().getValue();
2023
semanticInfoFieldName = builder.getSemanticInfoFieldName().getValue();

src/main/java/org/opensearch/neuralsearch/mapper/semanticFieldTypes/SemanticNumberFieldType.java renamed to src/main/java/org/opensearch/neuralsearch/mapper/semanticfieldtypes/SemanticNumberFieldType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package org.opensearch.neuralsearch.mapper.semanticFieldTypes;
5+
package org.opensearch.neuralsearch.mapper.semanticfieldtypes;
66

77
import lombok.Getter;
88
import lombok.NonNull;
@@ -12,6 +12,9 @@
1212
import org.opensearch.neuralsearch.mapper.SemanticFieldMapper;
1313
import org.opensearch.search.lookup.SearchLookup;
1414

15+
/**
16+
* A semantic field type that delegate the work to a number field type.
17+
*/
1518
public class SemanticNumberFieldType extends NumberFieldMapper.NumberFieldType {
1619
@Getter
1720
private SemanticFieldTypeParameters semanticFieldTypeParameters;

src/main/java/org/opensearch/neuralsearch/mapper/semanticFieldTypes/SemanticStringFieldType.java renamed to src/main/java/org/opensearch/neuralsearch/mapper/semanticfieldtypes/SemanticStringFieldType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package org.opensearch.neuralsearch.mapper.semanticFieldTypes;
5+
package org.opensearch.neuralsearch.mapper.semanticfieldtypes;
66

77
import lombok.Getter;
88
import lombok.NonNull;
@@ -27,6 +27,9 @@
2727
import java.util.List;
2828
import java.util.function.Supplier;
2929

30+
/**
31+
* A semantic field type that delegate the work to a string field type.
32+
*/
3033
public class SemanticStringFieldType extends StringFieldType {
3134
@Getter
3235
private SemanticFieldTypeParameters semanticFieldTypeParameters;

src/test/java/org/opensearch/neuralsearch/mapper/SemanticFieldMapperTestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.mockito.Mockito.when;
2424
import static org.opensearch.Version.CURRENT;
2525
import static org.opensearch.knn.index.KNNSettings.KNN_INDEX;
26-
import static org.opensearch.neuralsearch.constants.FieldConstants.TYPE;
26+
import static org.opensearch.neuralsearch.constants.MappingConstants.TYPE;
2727
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.MODEL_ID;
2828
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.RAW_FIELD_TYPE;
2929
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.SEARCH_MODEL_ID;

src/test/java/org/opensearch/neuralsearch/mapper/SemanticFieldMapperTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.opensearch.index.mapper.ParseContext;
1919
import org.opensearch.index.mapper.TextFieldMapper;
2020
import org.opensearch.index.mapper.WildcardFieldMapper;
21-
import org.opensearch.neuralsearch.mapper.semanticFieldTypes.SemanticStringFieldType;
21+
import org.opensearch.neuralsearch.mapper.semanticfieldtypes.SemanticStringFieldType;
2222
import org.opensearch.test.OpenSearchTestCase;
2323

2424
import java.io.IOException;
@@ -32,7 +32,7 @@
3232
import static org.mockito.Mockito.times;
3333
import static org.mockito.Mockito.verify;
3434
import static org.mockito.Mockito.when;
35-
import static org.opensearch.neuralsearch.constants.FieldConstants.TYPE;
35+
import static org.opensearch.neuralsearch.constants.MappingConstants.TYPE;
3636
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.MODEL_ID;
3737
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.RAW_FIELD_TYPE;
3838
import static org.opensearch.neuralsearch.constants.SemanticFieldConstants.SEARCH_MODEL_ID;
@@ -138,9 +138,8 @@ public void testTypeParser_parse_whenUnsupportedRawFieldType_thenException() {
138138
IllegalArgumentException.class,
139139
() -> TYPE_PARSER.parse(SemanticFieldMapperTestUtil.fieldName, node, parserContext)
140140
);
141-
final String expectedError = "raw_field_type: [unsupported] is not supported. It should be one of "
142-
+ "[text,keyword,match_only_text,wildcard,token_count,binary]";
143-
assertEquals(expectedError, exception.getMessage());
141+
final String expectedError = "raw_field_type: [unsupported] is not supported. It should be one of";
142+
assertTrue(exception.getMessage().contains(expectedError));
144143
}
145144

146145
private void assertBuilderParseParametersSuccessfully(

src/test/java/org/opensearch/neuralsearch/mapper/semanticFieldTypes/SemanticFieldTypeTests.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)