From 9dc20c73b1ca042450083dee1672fd79c4730a9e Mon Sep 17 00:00:00 2001 From: jzonthemtn Date: Tue, 10 Dec 2024 10:45:25 -0500 Subject: [PATCH] Changing logic to loop over the ranks and not the impression keyset. --- .../clickmodel/coec/CoecClickModel.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java index 381d2ee..af46886 100644 --- a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java +++ b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java @@ -343,34 +343,35 @@ public Map getRankAggregatedClickThrough() throws Exception { } - for(final Integer x : clickCounts.keySet()) { + for(int rank = 0; rank < parameters.getMaxRank(); rank++) { - if(impressionCounts.get(x) != null) { + if(impressionCounts.containsKey(rank)) { - if(clickCounts.get(x) != null) { + if(clickCounts.containsKey(rank)) { // Calculate the CTR by dividing the number of clicks by the number of impressions. - LOGGER.debug("Position = {}, Impression Counts = {}, Click Count = {}", x, impressionCounts.get(x), clickCounts.get(x)); - rankAggregatedClickThrough.put(x, clickCounts.get(x) / impressionCounts.get(x)); + LOGGER.debug("Position = {}, Impression Counts = {}, Click Count = {}", rank, impressionCounts.get(rank), clickCounts.get(rank)); + rankAggregatedClickThrough.put(rank, clickCounts.get(rank) / impressionCounts.get(rank)); } else { - // This document has impressions but no clicks so it's CTR is zero. - LOGGER.debug("Position = {}, Impression Counts = {}, Click Count = {}", x, clickCounts.get(x), clickCounts.get(x)); - rankAggregatedClickThrough.put(x, 0.0); + // This document has impressions but no clicks, so it's CTR is zero. + LOGGER.debug("Position = {}, Impression Counts = {}, No clicks so CTR is 0", rank, clickCounts.get(rank)); + rankAggregatedClickThrough.put(rank, 0.0); } } else { - // This will happen in the case where a document has a "click" event but not an "impression." This - // likely should not happen, but we will protect against an NPE anyway by setting the CTR to zero. - rankAggregatedClickThrough.put(x, (double) 0); + // No impressions so the clickthrough rate is 0. + LOGGER.debug("No impressions for rank {}, so using CTR of 0", rank); + rankAggregatedClickThrough.put(rank, (double) 0); } } + openSearchHelper.indexRankAggregatedClickthrough(rankAggregatedClickThrough); return rankAggregatedClickThrough;