Skip to content

Commit

Permalink
Merge pull request #59 from o19s/coec
Browse files Browse the repository at this point in the history
COEC changes
  • Loading branch information
jzonthemtn authored Dec 10, 2024
2 parents efaa6dd + 5400954 commit 97e86f8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion opensearch-search-quality-evaluation-plugin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ FROM opensearchproject/opensearch:2.18.0

RUN /usr/share/opensearch/bin/opensearch-plugin install --batch https://github.com/opensearch-project/user-behavior-insights/releases/download/2.18.0.2/opensearch-ubi-2.18.0.2.zip

ADD ./build/distributions/search-quality-evaluation-plugin-2.18.0.0.zip /tmp/search-quality-evaluation-plugin.zip
ADD ./build/distributions/search-quality-evaluation-plugin-0.0.1.zip /tmp/search-quality-evaluation-plugin.zip
RUN /usr/share/opensearch/bin/opensearch-plugin install --batch file:/tmp/search-quality-evaluation-plugin.zip
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
opensearchVersion = 2.18.0
evalVersion = 2.18.0.0
evalVersion = 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

curl -s "http://localhost:9200/click_through_rates/_search" | jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

curl -s "http://localhost:9200/rank_aggregated_ctr/_search" | jq
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class CoecClickModel extends ClickModel {

Expand Down Expand Up @@ -346,16 +345,28 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception {

for(final Integer x : clickCounts.keySet()) {

if(!(impressionCounts.get(x) == null)) {
if(impressionCounts.get(x) != null) {

// Calculate the CTR by dividing the number of clicks by the number of impressions.
LOGGER.debug("Position = {}, Click Count = {}, Event Count = {}", x, clickCounts.get(x), impressionCounts.get(x));
rankAggregatedClickThrough.put(x, clickCounts.get(x) / impressionCounts.get(x));
if(clickCounts.get(x) != null) {

// 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));

} 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);

}

} 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);

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ public void indexClickthroughRates(final Map<String, Set<ClickthroughRate>> clic

final BulkRequest request = new BulkRequest();

for(final String queryId : clickthroughRates.keySet()) {
for(final String userQuery : clickthroughRates.keySet()) {

for(final ClickthroughRate clickthroughRate : clickthroughRates.get(queryId)) {
for(final ClickthroughRate clickthroughRate : clickthroughRates.get(userQuery)) {

final Map<String, Object> jsonMap = new HashMap<>();
jsonMap.put("query_id", queryId);
jsonMap.put("user_query", userQuery);
jsonMap.put("clicks", clickthroughRate.getClicks());
jsonMap.put("events", clickthroughRate.getEvents());
jsonMap.put("ctr", clickthroughRate.getClickthroughRate());
Expand Down

0 comments on commit 97e86f8

Please sign in to comment.