Skip to content

Commit

Permalink
use string.format() instead of concatenation
Browse files Browse the repository at this point in the history
Signed-off-by: HenryL27 <[email protected]>
  • Loading branch information
HenryL27 committed Dec 1, 2023
1 parent f7eda01 commit d7c22e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.opensearch.neuralsearch.processor.factory;

import java.util.Locale;
import java.util.Map;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -54,15 +55,21 @@ public SearchResponseProcessor create(
Map<String, String> rerankerConfig = (Map<String, String>) config.remove(type.getLabel());
String modelId = rerankerConfig.get(CrossEncoderRerankProcessor.MODEL_ID_FIELD);
if (modelId == null) {
throw new IllegalArgumentException(CrossEncoderRerankProcessor.MODEL_ID_FIELD + " must be specified");
throw new IllegalArgumentException(
String.format(Locale.ROOT, "%s must be specified", CrossEncoderRerankProcessor.MODEL_ID_FIELD)
);
}
String rerankContext = rerankerConfig.get(CrossEncoderRerankProcessor.RERANK_CONTEXT_FIELD);
if (rerankContext == null) {
throw new IllegalArgumentException(CrossEncoderRerankProcessor.RERANK_CONTEXT_FIELD + " must be specified");
throw new IllegalArgumentException(
String.format(Locale.ROOT, "%s must be specified", CrossEncoderRerankProcessor.RERANK_CONTEXT_FIELD)
);
}
return new CrossEncoderRerankProcessor(description, tag, ignoreFailure, modelId, rerankContext, clientAccessor);
default:
throw new IllegalArgumentException("could not find constructor for reranker type " + type.getLabel());
throw new IllegalArgumentException(
String.format(Locale.ROOT, "could not find constructor for reranker type %s", type.getLabel())
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void generateScoringContext(
if (params.containsKey(QUERY_TEXT_FIELD)) {
if (params.containsKey(QUERY_TEXT_PATH_FIELD)) {
throw new IllegalArgumentException(
"Cannot specify both \"" + QUERY_TEXT_FIELD + "\" and \"" + QUERY_TEXT_PATH_FIELD + "\""
String.format(Locale.ROOT, "Cannot specify both \"%s\" and \"%s\"", QUERY_TEXT_FIELD, QUERY_TEXT_PATH_FIELD)
);
}
scoringContext.put(QUERY_TEXT_FIELD, (String) params.get(QUERY_TEXT_FIELD));
Expand All @@ -97,11 +98,15 @@ public void generateScoringContext(
// Get the text at the path
Object queryText = ObjectPath.eval(path, map);
if (!(queryText instanceof String)) {
throw new IllegalArgumentException(QUERY_TEXT_PATH_FIELD + " must point to a string field");
throw new IllegalArgumentException(
String.format(Locale.ROOT, "%s must point to a string field", QUERY_TEXT_PATH_FIELD)
);
}
scoringContext.put(QUERY_TEXT_FIELD, (String) queryText);
} else {
throw new IllegalArgumentException("Must specify either \"" + QUERY_TEXT_FIELD + "\" or \"" + QUERY_TEXT_PATH_FIELD + "\"");
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Must specify either \"%s\" or \"%s\"", QUERY_TEXT_FIELD, QUERY_TEXT_PATH_FIELD)
);
}
listener.onResponse(scoringContext);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.opensearch.neuralsearch.processor.rerank;

import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;

import lombok.Getter;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static RerankType from(String label) {
if (typeMaybe.isPresent()) {
return typeMaybe.get();
} else {
throw new IllegalArgumentException("Wrong rerank type name: " + label);
throw new IllegalArgumentException(String.format(Locale.ROOT, "Wrong rerank type name: %s", label));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public abstract void rescoreSearchResponse(

@Override
public void rerank(SearchResponse searchResponse, Map<String, Object> scoringContext, ActionListener<SearchResponse> listener) {
log.info("==================RERANKING==================");
try {
rescoreSearchResponse(searchResponse, scoringContext, ActionListener.wrap(scores -> {
// Assign new scores
Expand Down

0 comments on commit d7c22e9

Please sign in to comment.