From 29b397fdfa6e8637065d6b3ac1d150d0e4d4e3ff Mon Sep 17 00:00:00 2001 From: Martin Gaievski Date: Tue, 25 Jul 2023 10:36:10 -0700 Subject: [PATCH] Addressing review comments Signed-off-by: Martin Gaievski --- .../processor/NormalizationProcessor.java | 13 +++---------- .../processor/combination/ScoreCombiner.java | 4 ++-- .../MinMaxScoreNormalizationTechnique.java | 12 +++--------- .../processor/normalization/ScoreNormalizer.java | 2 +- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/opensearch/neuralsearch/processor/NormalizationProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/NormalizationProcessor.java index 5c7c948b2..5ae271397 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/NormalizationProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/NormalizationProcessor.java @@ -10,9 +10,7 @@ import java.util.Optional; import java.util.stream.Collectors; -import lombok.AccessLevel; import lombok.AllArgsConstructor; -import lombok.Getter; import lombok.extern.log4j.Log4j2; import org.opensearch.action.search.QueryPhaseResultConsumer; @@ -27,8 +25,6 @@ import org.opensearch.search.pipeline.SearchPhaseResultsProcessor; import org.opensearch.search.query.QuerySearchResult; -import com.google.common.annotations.VisibleForTesting; - /** * Processor for score normalization and combination on post query search results. Updates query results with * normalized and combined scores for next phase (typically it's FETCH) @@ -43,12 +39,9 @@ public class NormalizationProcessor implements SearchPhaseResultsProcessor { private final String tag; private final String description; - @VisibleForTesting - @Getter(AccessLevel.PACKAGE) - final ScoreNormalizationTechnique normalizationTechnique; - @Getter(AccessLevel.PACKAGE) - final ScoreCombinationTechnique combinationTechnique; - final NormalizationProcessorWorkflow normalizationWorkflow; + private final ScoreNormalizationTechnique normalizationTechnique; + private final ScoreCombinationTechnique combinationTechnique; + private final NormalizationProcessorWorkflow normalizationWorkflow; /** * Method abstracts functional aspect of score normalization and score combination. Exact methods for each processing stage diff --git a/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombiner.java b/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombiner.java index e6733a5a3..ebd40737a 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombiner.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/combination/ScoreCombiner.java @@ -65,7 +65,7 @@ protected float combineShardScores( Map normalizedScoresPerDoc = getNormalizedScoresPerDocument(topDocsPerSubQuery); // - create map of combined scores per doc id - Map combinedNormalizedScoresByDocId = combineScoresAndGetCombinedNormilizedScoresPerDocument( + Map combinedNormalizedScoresByDocId = combineScoresAndGetCombinedNormalizedScoresPerDocument( normalizedScoresPerDoc, scoreCombinationTechnique ); @@ -128,7 +128,7 @@ public Map getNormalizedScoresPerDocument(final List } @VisibleForTesting - protected Map combineScoresAndGetCombinedNormilizedScoresPerDocument( + protected Map combineScoresAndGetCombinedNormalizedScoresPerDocument( final Map normalizedScoresPerDocument, final ScoreCombinationTechnique scoreCombinationTechnique ) { diff --git a/src/main/java/org/opensearch/neuralsearch/processor/normalization/MinMaxScoreNormalizationTechnique.java b/src/main/java/org/opensearch/neuralsearch/processor/normalization/MinMaxScoreNormalizationTechnique.java index 316b23b3f..663e2d7d0 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/normalization/MinMaxScoreNormalizationTechnique.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/normalization/MinMaxScoreNormalizationTechnique.java @@ -25,12 +25,6 @@ public class MinMaxScoreNormalizationTechnique implements ScoreNormalizationTech private static final float MIN_SCORE = 0.001f; private static final float SINGLE_RESULT_SCORE = 1.0f; - private static final MinMaxScoreNormalizationTechnique INSTANCE = new MinMaxScoreNormalizationTechnique(); - - public static MinMaxScoreNormalizationTechnique getInstance() { - return INSTANCE; - } - /** * Min-max normalization method. * nscore = (score - min_score)/(max_score - min_score) @@ -69,7 +63,7 @@ public void normalize(final List queryTopDocs) { } } - private float[] getMaxScores(List queryTopDocs, int numOfSubqueries) { + private float[] getMaxScores(final List queryTopDocs, final int numOfSubqueries) { float[] maxScores = new float[numOfSubqueries]; Arrays.fill(maxScores, Float.MIN_VALUE); for (CompoundTopDocs compoundQueryTopDocs : queryTopDocs) { @@ -90,7 +84,7 @@ private float[] getMaxScores(List queryTopDocs, int numOfSubque return maxScores; } - private float[] getMinScores(List queryTopDocs, int numOfScores) { + private float[] getMinScores(final List queryTopDocs, final int numOfScores) { float[] minScores = new float[numOfScores]; Arrays.fill(minScores, Float.MAX_VALUE); for (CompoundTopDocs compoundQueryTopDocs : queryTopDocs) { @@ -111,7 +105,7 @@ private float[] getMinScores(List queryTopDocs, int numOfScores return minScores; } - private float normalizeSingleScore(float score, float minScore, float maxScore) { + private float normalizeSingleScore(final float score, final float minScore, final float maxScore) { // edge case when there is only one score and min and max scores are same if (Floats.compare(maxScore, minScore) == 0 && Floats.compare(maxScore, score) == 0) { return SINGLE_RESULT_SCORE; diff --git a/src/main/java/org/opensearch/neuralsearch/processor/normalization/ScoreNormalizer.java b/src/main/java/org/opensearch/neuralsearch/processor/normalization/ScoreNormalizer.java index acdef8d46..5b8b7b1ca 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/normalization/ScoreNormalizer.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/normalization/ScoreNormalizer.java @@ -23,7 +23,7 @@ public void normalizeScores(final List queryTopDocs, final Scor } } - private boolean canQueryResultsBeNormalized(List queryTopDocs) { + private boolean canQueryResultsBeNormalized(final List queryTopDocs) { return queryTopDocs.stream().filter(Objects::nonNull).anyMatch(topDocs -> topDocs.getCompoundTopDocs().size() > 0); } }