Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski committed Jul 25, 2023
1 parent 74b23b2 commit f2ba35a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -69,7 +63,7 @@ public void normalize(final List<CompoundTopDocs> queryTopDocs) {
}
}

private float[] getMaxScores(List<CompoundTopDocs> queryTopDocs, int numOfSubqueries) {
private float[] getMaxScores(final List<CompoundTopDocs> queryTopDocs, final int numOfSubqueries) {
float[] maxScores = new float[numOfSubqueries];
Arrays.fill(maxScores, Float.MIN_VALUE);
for (CompoundTopDocs compoundQueryTopDocs : queryTopDocs) {
Expand All @@ -90,7 +84,7 @@ private float[] getMaxScores(List<CompoundTopDocs> queryTopDocs, int numOfSubque
return maxScores;
}

private float[] getMinScores(List<CompoundTopDocs> queryTopDocs, int numOfScores) {
private float[] getMinScores(final List<CompoundTopDocs> queryTopDocs, final int numOfScores) {
float[] minScores = new float[numOfScores];
Arrays.fill(minScores, Float.MAX_VALUE);
for (CompoundTopDocs compoundQueryTopDocs : queryTopDocs) {
Expand All @@ -111,7 +105,7 @@ private float[] getMinScores(List<CompoundTopDocs> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void normalizeScores(final List<CompoundTopDocs> queryTopDocs, final Scor
}
}

private boolean canQueryResultsBeNormalized(List<CompoundTopDocs> queryTopDocs) {
private boolean canQueryResultsBeNormalized(final List<CompoundTopDocs> queryTopDocs) {
return queryTopDocs.stream().filter(Objects::nonNull).anyMatch(topDocs -> topDocs.getCompoundTopDocs().size() > 0);
}
}

0 comments on commit f2ba35a

Please sign in to comment.