diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java index 0e520febdb8..da8651e6a24 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResponse.java @@ -38,42 +38,64 @@ import java.util.Map; * Documents of unknown quality - i.e. those that haven't been supplied in the set of annotated documents but have been returned * by the search are not taken into consideration when computing precision at n - they are ignored. * - * TODO get rid of either this or RankEvalResult **/ +//TODO instead of just returning averages over complete results, think of other statistics, micro avg, macro avg, partial results public class RankEvalResponse extends ActionResponse implements ToXContent { - - private RankEvalResult qualityResult; + /**ID of QA specification this result was generated for.*/ + private String specId; + /**Average precision observed when issuing query intents with this specification.*/ + private double qualityLevel; + /**Mapping from intent id to all documents seen for this intent that were not annotated.*/ + private Map> unknownDocs; public RankEvalResponse() { - } + @SuppressWarnings("unchecked") public RankEvalResponse(StreamInput in) throws IOException { super.readFrom(in); - this.qualityResult = new RankEvalResult(in); + this.specId = in.readString(); + this.qualityLevel = in.readDouble(); + this.unknownDocs = (Map>) in.readGenericValue(); + } + + public RankEvalResponse(String specId, double qualityLevel, Map> unknownDocs) { + this.specId = specId; + this.qualityLevel = qualityLevel; + this.unknownDocs = unknownDocs; + } + + public String getSpecId() { + return specId; + } + + public double getQualityLevel() { + return qualityLevel; + } + + public Map> getUnknownDocs() { + return unknownDocs; + } + + @Override + public String toString() { + return "RankEvalResult, ID :[" + specId + "], quality: " + qualityLevel + ", unknown docs: " + unknownDocs; } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - qualityResult.writeTo(out); - } - - public void setRankEvalResult(RankEvalResult result) { - this.qualityResult = result; - } - - public RankEvalResult getRankEvalResult() { - return qualityResult; + out.writeString(specId); + out.writeDouble(qualityLevel); + out.writeGenericValue(getUnknownDocs()); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("rank_eval"); - builder.field("spec_id", qualityResult.getSpecId()); - builder.field("quality_level", qualityResult.getQualityLevel()); + builder.field("spec_id", specId); + builder.field("quality_level", qualityLevel); builder.startArray("unknown_docs"); - Map> unknownDocs = qualityResult.getUnknownDocs(); for (String key : unknownDocs.keySet()) { builder.startObject(); builder.field(key, unknownDocs.get(key)); diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResult.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResult.java deleted file mode 100644 index 726b3c82aa7..00000000000 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalResult.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.rankeval; - -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; - -import java.io.IOException; -import java.util.Collection; -import java.util.Map; - -/** - * For each precision at n computation the id of the search request specification used to generate search requests is returned - * for reference. In addition the averaged precision and the ids of all documents returned but not found annotated is returned. - * */ -// TODO do we need an extra class for this or it RankEvalResponse enough? -// TODO instead of just returning averages over complete results, think of other statistics, micro avg, macro avg, partial results -public class RankEvalResult implements Writeable { - /**ID of QA specification this result was generated for.*/ - private String specId; - /**Average precision observed when issuing query intents with this specification.*/ - private double qualityLevel; - /**Mapping from intent id to all documents seen for this intent that were not annotated.*/ - private Map> unknownDocs; - - @SuppressWarnings("unchecked") - public RankEvalResult(StreamInput in) throws IOException { - this.specId = in.readString(); - this.qualityLevel = in.readDouble(); - this.unknownDocs = (Map>) in.readGenericValue(); - } - - public RankEvalResult(String specId, double quality, Map> unknownDocs) { - this.specId = specId; - this.qualityLevel = quality; - this.unknownDocs = unknownDocs; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(specId); - out.writeDouble(qualityLevel); - out.writeGenericValue(getUnknownDocs()); - } - - public String getSpecId() { - return specId; - } - - public double getQualityLevel() { - return qualityLevel; - } - - public Map> getUnknownDocs() { - return unknownDocs; - } - - @Override - public String toString() { - return "RankEvalResult, ID :[" + specId + "], quality: " + qualityLevel + ", unknown docs: " + unknownDocs; - } -} \ No newline at end of file diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/TransportRankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/TransportRankEvalAction.java index 7b13014e310..f2e97068e62 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/TransportRankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/TransportRankEvalAction.java @@ -105,10 +105,8 @@ public class TransportRankEvalAction extends HandledTransportAction>> entrySet = result.getUnknownDocs().entrySet(); + assertEquals(specId, response.getSpecId()); + assertEquals(1.0, response.getQualityLevel(), Double.MIN_VALUE); + Set>> entrySet = response.getUnknownDocs().entrySet(); assertEquals(2, entrySet.size()); for (Entry> entry : entrySet) { if (entry.getKey() == "amsterdam_query") {