Skip to content

Commit

Permalink
simplify the code given toInt in NumberUtils
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
  • Loading branch information
yuye-aws committed Apr 28, 2024
1 parent d155a1b commit aa08ffb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ private int getMaxTokenCount(final Map<String, Object> sourceAndMetadataMap) {
}
// if the index is specified in the metadata, read maxTokenCount from the index setting
String maxTokenCountString = indexMetadata.getSettings().get("index.analyze.max_token_count");
// if maxTokenCount is not specified in the index, return the default setting
if (Objects.isNull(maxTokenCountString)) {
return defaultMaxTokenCount;
}
return NumberUtils.toInt(maxTokenCountString, defaultMaxTokenCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryRewriteContext;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.knn.index.query.KNNQueryBuilder;
import org.opensearch.neuralsearch.ml.MLCommonsClientAccessor;
import org.opensearch.neuralsearch.util.NeuralSearchClusterUtil;

Expand Down Expand Up @@ -289,18 +288,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) {
// create a new builder. Once the supplier's value gets set, we return a KNNQueryBuilder. Otherwise, we just
// return the current unmodified query builder.
if (vectorSupplier() != null) {
if (vectorSupplier().get() == null) {
return this;
}
KNNQueryBuilder knnQueryBuilder = new KNNQueryBuilder(fieldName(), vectorSupplier.get()).filter(filter());
if (maxDistance != null) {
knnQueryBuilder.maxDistance(maxDistance);
} else if (minScore != null) {
knnQueryBuilder.minScore(minScore);
} else {
knnQueryBuilder.k(k);
}
return knnQueryBuilder;
return this;
}

SetOnce<float[]> vectorSetOnce = new SetOnce<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.query.TermQueryBuilder;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.VectorDataType;
import org.opensearch.knn.index.mapper.KNNVectorFieldMapper;
import org.opensearch.knn.index.query.KNNQuery;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void testDoToQuery_whenOneSubquery_thenBuildSuccessfully() {
when(mockKNNVectorField.getDimension()).thenReturn(4);
when(mockKNNVectorField.getVectorDataType()).thenReturn(VectorDataType.FLOAT);
when(mockQueryShardContext.fieldMapper(eq(VECTOR_FIELD_NAME))).thenReturn(mockKNNVectorField);
when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);
// when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);

NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder().fieldName(VECTOR_FIELD_NAME)
.queryText(QUERY_TEXT)
Expand Down Expand Up @@ -119,7 +118,7 @@ public void testDoToQuery_whenMultipleSubqueries_thenBuildSuccessfully() {
when(mockQueryShardContext.index()).thenReturn(dummyIndex);
when(mockKNNVectorField.getDimension()).thenReturn(4);
when(mockKNNVectorField.getVectorDataType()).thenReturn(VectorDataType.FLOAT);
when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);
// when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);
when(mockQueryShardContext.fieldMapper(eq(VECTOR_FIELD_NAME))).thenReturn(mockKNNVectorField);

NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder().fieldName(VECTOR_FIELD_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.knn.index.SpaceType;
import org.opensearch.knn.index.mapper.KNNVectorFieldMapper;
import org.opensearch.knn.index.query.KNNQueryBuilder;

Expand Down Expand Up @@ -118,7 +117,7 @@ public void testRewrite_whenRewriteQuery_thenSuccessful() {
when(mockQueryShardContext.index()).thenReturn(dummyIndex);
when(mockKNNVectorField.getDimension()).thenReturn(4);
when(mockQueryShardContext.fieldMapper(eq(VECTOR_FIELD_NAME))).thenReturn(mockKNNVectorField);
when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);
// when(mockKNNVectorField.getSpaceType()).thenReturn(SpaceType.L2);
KNNQueryBuilder knnQueryBuilder = new KNNQueryBuilder(VECTOR_FIELD_NAME, VECTOR_QUERY, K);
Query knnQuery = knnQueryBuilder.toQuery(mockQueryShardContext);

Expand Down

0 comments on commit aa08ffb

Please sign in to comment.