Fixing compilation issues and tests after merging in master

This commit is contained in:
Christoph Büscher 2017-07-14 19:23:35 +02:00
parent 6d999f074a
commit 887ed68cf2
8 changed files with 27 additions and 49 deletions

View File

@ -22,14 +22,12 @@ package org.elasticsearch.index.rankeval;
import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.io.IOException;
@ -236,7 +234,7 @@ public class RatedRequest extends ToXContentToBytes implements Writeable {
private static final ParseField FIELDS_FIELD = new ParseField("summary_fields");
private static final ParseField TEMPLATE_ID_FIELD = new ParseField("template_id");
private static final ConstructingObjectParser<RatedRequest, QueryParseContext> PARSER =
private static final ConstructingObjectParser<RatedRequest, Void> PARSER =
new ConstructingObjectParser<>("requests",
a -> new RatedRequest((String) a[0], (List<RatedDocument>) a[1],
(SearchSourceBuilder) a[2], (Map<String, Object>) a[3], (String) a[4]));
@ -246,20 +244,9 @@ public class RatedRequest extends ToXContentToBytes implements Writeable {
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), (p, c) -> {
return RatedDocument.fromXContent(p);
}, RATINGS_FIELD);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> {
try {
return SearchSourceBuilder.fromXContent(c);
} catch (IOException ex) {
throw new ParsingException(p.getTokenLocation(), "error parsing request", ex);
}
}, REQUEST_FIELD);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> {
try {
return (Map) p.map();
} catch (IOException ex) {
throw new ParsingException(p.getTokenLocation(), "error parsing ratings", ex);
}
}, PARAMS_FIELD);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) ->
SearchSourceBuilder.fromXContent(p), REQUEST_FIELD);
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> (Map) p.map(), PARAMS_FIELD);
PARSER.declareStringArray(RatedRequest::setSummaryFields, FIELDS_FIELD);
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), TEMPLATE_ID_FIELD);
}
@ -275,7 +262,7 @@ public class RatedRequest extends ToXContentToBytes implements Writeable {
* "ratings": [{ "1": 1 }, { "2": 0 }, { "3": 1 } ] }
*/
public static RatedRequest fromXContent(XContentParser parser) {
return PARSER.apply(parser, new QueryParseContext(parser));
return PARSER.apply(parser, null);
}
@Override

View File

@ -32,7 +32,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.TemplateScript;
@ -111,10 +110,8 @@ public class TransportRankEvalAction
String templateId = ratedRequest.getTemplateId();
TemplateScript.Factory templateScript = scriptsWithoutParams.get(templateId);
String resolvedRequest = templateScript.newInstance(params).execute();
try (XContentParser subParser = createParser(namedXContentRegistry, new BytesArray(resolvedRequest),
XContentType.JSON)) {
QueryParseContext parseContext = new QueryParseContext(subParser);
ratedSearchSource = SearchSourceBuilder.fromXContent(parseContext);
try (XContentParser subParser = createParser(namedXContentRegistry, new BytesArray(resolvedRequest), XContentType.JSON)) {
ratedSearchSource = SearchSourceBuilder.fromXContent(subParser);
} catch (IOException e) {
listener.onFailure(e);
}

View File

@ -62,7 +62,7 @@ public class DiscountedCumulativeGainTests extends ESTestCase {
rated.add(new RatedDocument("index", "type", Integer.toString(i), relevanceRatings[i]));
hits[i] = new SearchHit(i, Integer.toString(i), new Text("type"),
Collections.emptyMap());
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0));
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0, null));
}
DiscountedCumulativeGain dcg = new DiscountedCumulativeGain();
assertEquals(13.84826362927298, dcg.evaluate("id", hits, rated).getQualityLevel(), 0.00001);
@ -114,7 +114,7 @@ public class DiscountedCumulativeGainTests extends ESTestCase {
}
hits[i] = new SearchHit(i, Integer.toString(i), new Text("type"),
Collections.emptyMap());
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0));
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0, null));
}
DiscountedCumulativeGain dcg = new DiscountedCumulativeGain();
EvalQueryQuality result = dcg.evaluate("id", hits, rated);
@ -171,7 +171,7 @@ public class DiscountedCumulativeGainTests extends ESTestCase {
for (int i = 0; i < 4; i++) {
hits[i] = new SearchHit(i, Integer.toString(i), new Text("type"),
Collections.emptyMap());
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0));
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0, null));
}
DiscountedCumulativeGain dcg = new DiscountedCumulativeGain();
EvalQueryQuality result = dcg.evaluate("id", hits, ratedDocs);

View File

@ -126,7 +126,7 @@ public class PrecisionTests extends ESTestCase {
// add an unlabeled search hit
SearchHit[] searchHits = Arrays.copyOf(toSearchHits(rated, "test", "testtype"), 3);
searchHits[2] = new SearchHit(2, "2", new Text("testtype"), Collections.emptyMap());
searchHits[2].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0));
searchHits[2].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0, null));
EvalQueryQuality evaluated = (new Precision()).evaluate("id", searchHits, rated);
assertEquals((double) 2 / 3, evaluated.getQualityLevel(), 0.00001);
@ -148,7 +148,7 @@ public class PrecisionTests extends ESTestCase {
SearchHit[] hits = new SearchHit[5];
for (int i = 0; i < 5; i++) {
hits[i] = new SearchHit(i, i + "", new Text("type"), Collections.emptyMap());
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0));
hits[i].shard(new SearchShardTarget("testnode", new Index("index", "uuid"), 0, null));
}
EvalQueryQuality evaluated = (new Precision()).evaluate("id", hits,
Collections.emptyList());
@ -227,7 +227,7 @@ public class PrecisionTests extends ESTestCase {
RankEvalTestHelper.copy(testItem, Precision::new));
}
private Precision mutateTestItem(Precision original) {
private static Precision mutateTestItem(Precision original) {
boolean ignoreUnlabeled = original.getIgnoreUnlabeled();
int relevantThreshold = original.getRelevantRatingThreshold();
Precision precision = new Precision();
@ -246,7 +246,7 @@ public class PrecisionTests extends ESTestCase {
SearchHit[] hits = new SearchHit[rated.size()];
for (int i = 0; i < rated.size(); i++) {
hits[i] = new SearchHit(i, i + "", new Text(type), Collections.emptyMap());
hits[i].shard(new SearchShardTarget("testnode", new Index(index, "uuid"), 0));
hits[i].shard(new SearchShardTarget("testnode", new Index(index, "uuid"), 0, null));
}
return hits;
}

View File

@ -68,24 +68,18 @@ public class RankEvalSpecTests extends ESTestCase {
Collection<ScriptWithId> templates = null;
if (randomBoolean()) {
final Map<String, Object> params = randomBoolean() ? Collections.emptyMap()
: Collections.singletonMap("key", "value");
ScriptType scriptType = randomFrom(ScriptType.values());
final Map<String, Object> params = randomBoolean() ? Collections.emptyMap() : Collections.singletonMap("key", "value");
String script;
if (scriptType == ScriptType.INLINE) {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.startObject();
builder.field("field", randomAlphaOfLengthBetween(1, 5));
builder.endObject();
script = builder.string();
}
} else {
script = randomAlphaOfLengthBetween(1, 5);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.startObject();
builder.field("field", randomAlphaOfLengthBetween(1, 5));
builder.endObject();
script = builder.string();
}
templates = new HashSet<>();
templates.add(new ScriptWithId("templateId",
new Script(scriptType, Script.DEFAULT_TEMPLATE_LANG, script, params)));
new Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, script, params)));
Map<String, Object> templateParams = new HashMap<>();
templateParams.put("key", "value");

View File

@ -66,7 +66,7 @@ public class RatedDocumentTests extends ESTestCase {
RankEvalTestHelper.copy(testItem, RatedDocument::new));
}
public void testInvalidParsing() throws IOException {
public void testInvalidParsing() {
expectThrows(IllegalArgumentException.class,
() -> new RatedDocument(null, "abc", "abc", 10));
expectThrows(IllegalArgumentException.class, () -> new RatedDocument("", "abc", "abc", 10));

View File

@ -86,7 +86,7 @@ public class RatedRequestsTests extends ESTestCase {
SearchSourceBuilder testRequest = null;
if (randomBoolean() || forceRequest) {
testRequest = new SearchSourceBuilder();
testRequest.size(randomInt());
testRequest.size(randomIntBetween(0, Integer.MAX_VALUE));
testRequest.query(new MatchAllQueryBuilder());
} else {
int randomSize = randomIntBetween(1, 10);
@ -198,7 +198,7 @@ public class RatedRequestsTests extends ESTestCase {
new NamedWriteableRegistry(namedWriteables)));
}
private RatedRequest mutateTestItem(RatedRequest original) {
private static RatedRequest mutateTestItem(RatedRequest original) {
String id = original.getId();
SearchSourceBuilder testRequest = original.getTestRequest();
List<RatedDocument> ratedDocs = original.getRatedDocs();

View File

@ -156,12 +156,12 @@ public class ReciprocalRankTests extends ESTestCase {
SearchHit[] hits = new SearchHit[to + 1 - from];
for (int i = from; i <= to; i++) {
hits[i] = new SearchHit(i, i + "", new Text(type), Collections.emptyMap());
hits[i].shard(new SearchShardTarget("testnode", new Index(index, "uuid"), 0));
hits[i].shard(new SearchShardTarget("testnode", new Index(index, "uuid"), 0, null));
}
return hits;
}
private ReciprocalRank createTestItem() {
private static ReciprocalRank createTestItem() {
ReciprocalRank testItem = new ReciprocalRank();
testItem.setRelevantRatingThreshhold(randomIntBetween(0, 20));
return testItem;
@ -182,7 +182,7 @@ public class ReciprocalRankTests extends ESTestCase {
RankEvalTestHelper.copy(testItem, ReciprocalRank::new));
}
private ReciprocalRank mutateTestItem(ReciprocalRank testItem) {
private static ReciprocalRank mutateTestItem(ReciprocalRank testItem) {
int relevantThreshold = testItem.getRelevantRatingThreshold();
ReciprocalRank rank = new ReciprocalRank();
rank.setRelevantRatingThreshhold(