Skip to content

Commit

Permalink
fix retriever tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Jul 4, 2024
1 parent f127e7b commit 165604d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,10 @@ public ActionRequestValidationException validate(ActionRequestValidationExceptio
specified.add(RANK_FIELD.getPreferredName());
}
if (specified.isEmpty() == false) {
validationException = addValidationError("cannot specify [" + RETRIEVER.getPreferredName() + "] and " + specified, validationException);
validationException = addValidationError(
"cannot specify [" + RETRIEVER.getPreferredName() + "] and " + specified,
validationException
);
}
}
if (isScroll) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [query]", iae.getMessage());
}

Expand All @@ -44,25 +47,37 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [knn]", iae.getMessage());
}

try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"search_after\": [1], \"retriever\":{\"standard\":{}}}")) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [search_after]", iae.getMessage());
}

try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"terminate_after\": 1, \"retriever\":{\"standard\":{}}}")) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [terminate_after]", iae.getMessage());
}

try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"sort\": [\"field\"], \"retriever\":{\"standard\":{}}}")) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [sort]", iae.getMessage());
}

Expand All @@ -73,13 +88,19 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [rescore]", iae.getMessage());
}

try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"min_score\": 2, \"retriever\":{\"standard\":{}}}")) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [min_score]", iae.getMessage());
}

Expand All @@ -90,7 +111,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("cannot specify [retriever] and [query, terminate_after, min_score]", iae.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[search_after] cannot be used in children of compound retrievers", iae.getMessage());
}

Expand All @@ -60,7 +63,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[terminate_after] cannot be used in children of compound retrievers", iae.getMessage());
}

Expand All @@ -71,7 +77,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[sort] cannot be used in children of compound retrievers", iae.getMessage());
}

Expand All @@ -82,7 +91,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[min_score] cannot be used in children of compound retrievers", iae.getMessage());
}

Expand All @@ -94,7 +106,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[collapse] cannot be used in children of compound retrievers", iae.getMessage());
}

Expand All @@ -105,7 +120,10 @@ public void testRetrieverExtractionErrors() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[rank] cannot be used in children of compound retrievers", iae.getMessage());
}
}
Expand All @@ -119,7 +137,10 @@ public void testRetrieverBuilderParsingMaxDepth() throws IOException {
)
) {
SearchSourceBuilder ssb = new SearchSourceBuilder();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> ssb.parseXContent(parser, true, nf -> true));
IllegalArgumentException iae = expectThrows(
IllegalArgumentException.class,
() -> ssb.parseXContent(parser, true, nf -> true).rewrite(null)
);
assertEquals("[1:65] [rrf] failed to parse field [retrievers]", iae.getMessage());
assertEquals(
"the nested depth of the [standard] retriever exceeds the maximum nested depth [2] for retrievers",
Expand Down

0 comments on commit 165604d

Please sign in to comment.