diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-10-12 17:23:15 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-10-12 17:23:15 +0200 |
commit | a4bea045fa2b78dd2258020ac66413cff4cb39d7 (patch) | |
tree | 56ed34bc88bce5bf29d1a728ed1ab23755267b07 /container-search/src | |
parent | 9512873b312a5348e29662c1bcd0e07a385c44e1 (diff) |
A group hit is not meta since it contains result data
Diffstat (limited to 'container-search/src')
8 files changed, 75 insertions, 14 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/Group.java b/container-search/src/main/java/com/yahoo/search/grouping/result/Group.java index 5abecbca566..158cf17d154 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/Group.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/Group.java @@ -24,13 +24,15 @@ public class Group extends HitGroup { */ public Group(GroupId groupId, Relevance rel) { super(groupId.toString(), rel); + setMeta(false); + setAuxiliary(true); this.groupId = groupId; } /** * Returns the id of this group. This is a model of the otherwise flattened {@link #getId() hit id}. * - * @return The group id. + * @return the group id */ public GroupId getGroupId() { return groupId; @@ -41,8 +43,8 @@ public class Group extends HitGroup { * com.yahoo.search.grouping.request.EachOperation} that generated the list. This method returns null if no such * list was found. * - * @param label The label of the list to return. - * @return The requested list, or null. + * @param label the label of the list to return + * @return the requested list, or null */ public HitList getHitList(String label) { for (Hit hit : this) { diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/GroupId.java b/container-search/src/main/java/com/yahoo/search/grouping/result/GroupId.java index 80ad9af96dd..2cf88372014 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/GroupId.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/GroupId.java @@ -41,4 +41,5 @@ public abstract class GroupId { public String toString() { return image; } + } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/GroupList.java b/container-search/src/main/java/com/yahoo/search/grouping/result/GroupList.java index 8c15bb0d824..d3d48358bc5 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/GroupList.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/GroupList.java @@ -16,9 +16,10 @@ public class GroupList extends AbstractList { /** * Constructs a new instance of this class. * - * @param label The label to assign to this. + * @param label the label to assign to this */ public GroupList(String label) { super("grouplist", label); } + } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/result/RootId.java b/container-search/src/main/java/com/yahoo/search/grouping/result/RootId.java index 3f3e883d135..6b7635664fe 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/result/RootId.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/result/RootId.java @@ -11,4 +11,5 @@ public class RootId extends GroupId { public RootId(int id) { super("root", id); } + } diff --git a/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java b/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java index ace262f053c..5c897245e64 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java +++ b/container-search/src/main/java/com/yahoo/search/handler/HttpSearchResponse.java @@ -58,13 +58,10 @@ public class HttpSearchResponse extends ExtendedResponse { } /** - * Copy custom HTTP headers from the search result over to the HTTP - * response. + * Copy custom HTTP headers from the search result over to the HTTP response. * - * @param outputHeaders - * the headers which will be sent to a client - * @param searchHeaders - * the headers from the search result, or null + * @param outputHeaders the headers which will be sent to a client + * @param searchHeaders the headers from the search result, or null */ private static void populateHeaders(HeaderFields outputHeaders, ListMap<String, String> searchHeaders) { diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java index 057b607460c..a38dd5dc67a 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java @@ -293,7 +293,7 @@ public class SearchHandler extends LoggingRequestHandler { @Override public Optional<Request.RequestType> getRequestType() { return Optional.of(Request.RequestType.READ); } - private int getHttpResponseStatus(com.yahoo.container.jdisc.HttpRequest httpRequest, Result result) { + static int getHttpResponseStatus(com.yahoo.container.jdisc.HttpRequest httpRequest, Result result) { boolean benchmarkOutput = VespaHeaders.benchmarkOutput(httpRequest); if (benchmarkOutput) { return VespaHeaders.getEagerErrorStatus(result.hits().getError(), diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java b/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java index b752467f418..a9601ee5ec2 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchResponse.java @@ -43,8 +43,9 @@ public class SearchResponse { static boolean isSuccess(Result r) { if (r.hits().getErrorHit() == null) return true; - for (Hit hit : r.hits()) - if ( ! hit.isMeta()) return true; // contains data : success + for (Hit hit : r.hits()) { + if (!hit.isMeta()) return true; // contains data : success + } return false; } diff --git a/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java b/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java index 33b320f0de7..e666a999529 100644 --- a/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java +++ b/container-search/src/test/java/com/yahoo/search/handler/SearchHandlerTest.java @@ -15,9 +15,14 @@ import com.yahoo.net.HostName; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; +import com.yahoo.search.grouping.result.Group; +import com.yahoo.search.grouping.result.GroupId; +import com.yahoo.search.grouping.result.RootId; import com.yahoo.search.rendering.XmlRenderer; +import com.yahoo.search.result.ErrorHit; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; +import com.yahoo.search.result.Relevance; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.config.test.SearchChainConfigurerTestCase; import org.junit.After; @@ -27,6 +32,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.net.URI; @@ -207,6 +213,7 @@ public class SearchHandlerTest { testInvalidQueryParam(newDriver); } } + @Test public void testInvalidQueryParamWithoutQueryProfile() { testInvalidQueryParam(driver); @@ -221,11 +228,24 @@ public class SearchHandlerTest { } @Test + public void testResultStatus() { + assertEquals(200, httpStatus(result().build())); + assertEquals(200, httpStatus(result().withHit().build())); + assertEquals(200, httpStatus(result().withGroups().build())); + assertEquals(200, httpStatus(result().withGroups().withHit().build())); + + assertEquals(500, httpStatus(result().withError().build())); + assertEquals(200, httpStatus(result().withError().withHit().build())); + assertEquals(200, httpStatus(result().withError().withGroups().build())); + assertEquals(200, httpStatus(result().withError().withGroups().withHit().build())); + } + + @Test public void testWebServiceStatus() { RequestHandlerTestDriver.MockResponseHandler responseHandler = driver.sendRequest("http://localhost/search/?query=web_service_status_code"); String response = responseHandler.readAll(); - assertThat(responseHandler.getStatus(), is(406)); + assertEquals(406, responseHandler.getStatus()); assertThat(response, containsString("\"code\":" + 406)); } @@ -334,6 +354,19 @@ public class SearchHandlerTest { return new RequestHandlerTestDriver(newSearchHandler); } + private int httpStatus(Result result) { + var jDiscRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(driver.jDiscDriver(), + URI.create("ignored"), + com.yahoo.jdisc.http.HttpRequest.Method.GET); + try { + var request = new HttpRequest(jDiscRequest, new ByteArrayInputStream(new byte[0])); + return SearchHandler.getHttpResponseStatus(request, result); + } + finally { + jDiscRequest.release(); + } + } + /** Referenced from config */ public static class TestSearcher extends Searcher { @@ -503,4 +536,29 @@ public class SearchHandlerTest { } + private ResultBuilder result() { return new ResultBuilder(); } + + private static class ResultBuilder { + + Result result = new Result(new Query()); + + public ResultBuilder withHit() { + result.hits().add(new Hit("regularHit:1")); + return this; + } + + public ResultBuilder withGroups() { + result.hits().add(new Group(new RootId(1), new Relevance(1.0))); + return this; + } + + public ResultBuilder withError() { + result.hits().addError(ErrorMessage.createUnspecifiedError("Test error")); + return this; + } + + public Result build() { return result; } + + } + } |