Search in sources :

Example 76 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class JsonRendererTestCase method test.

@Test
public final void test() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"fields\": {\n" + "                            \"c\": \"d\",\n" + "                            \"uri\": \"http://localhost/1\"\n" + "                        },\n" + "                        \"id\": \"http://localhost/1\",\n" + "                        \"relevance\": 0.9,\n" + "                        \"types\": [\n" + "                            \"summary\"\n" + "                        ]\n" + "                    }\n" + "                ],\n" + "                \"id\": \"usual\",\n" + "                \"relevance\": 1.0\n" + "            },\n" + "            {\n" + "                \"fields\": {\n" + "                    \"e\": \"f\"\n" + "                },\n" + "                \"id\": \"type grouphit\",\n" + "                \"relevance\": 1.0,\n" + "                \"types\": [\n" + "                    \"grouphit\"\n" + "                ]\n" + "            },\n" + "            {\n" + "                \"fields\": {\n" + "                    \"b\": \"foo\",\n" + "                    \"uri\": \"http://localhost/\"\n" + "                },\n" + "                \"id\": \"http://localhost/\",\n" + "                \"relevance\": 0.95,\n" + "                \"types\": [\n" + "                    \"summary\"\n" + "                ]\n" + "            }\n" + "        ],\n" + "        \"coverage\": {\n" + "            \"coverage\": 100,\n" + "            \"documents\": 500,\n" + "            \"full\": true,\n" + "            \"nodes\": 1,\n" + "            \"results\": 1,\n" + "            \"resultsFull\": 1\n" + "        },\n" + "        \"errors\": [\n" + "            {\n" + "                \"code\": 18,\n" + "                \"message\": \"boom\",\n" + "                \"summary\": \"Internal server error.\"\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}";
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    Execution execution = new Execution(Execution.Context.createContextStub());
    Result r = new Result(q);
    r.setCoverage(new Coverage(500, 1, true));
    FastHit h = new FastHit("http://localhost/", .95);
    h.setField("$a", "Hello, world.");
    h.setField("b", "foo");
    r.hits().add(h);
    HitGroup g = new HitGroup("usual");
    h = new FastHit("http://localhost/1", .90);
    h.setField("c", "d");
    g.add(h);
    r.hits().add(g);
    HitGroup gg = new HitGroup("type grouphit");
    gg.types().add("grouphit");
    gg.setField("e", "f");
    r.hits().add(gg);
    r.hits().addError(ErrorMessage.createInternalServerError("boom"));
    String summary = render(execution, r);
    assertEqualJson(expected, summary);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) Coverage(com.yahoo.search.result.Coverage) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 77 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class JsonRendererTestCase method testTracingWithEmptySubtree.

@SuppressWarnings("unchecked")
@Test
public final void testTracingWithEmptySubtree() throws IOException, InterruptedException, ExecutionException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    },\n" + "    \"trace\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"message\": \"No query profile is used\"\n" + "            },\n" + "            {\n" + "                \"message\": \"Resolved properties:\\ntracelevel=10 (value from request)\\nquery=a (value from request)\\n\"\n" + "            },\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"timestamp\": 42\n" + "                    }\n" + "                ]\n" + "            }\n" + "        ]\n" + "    }\n" + "}";
    Query q = new Query("/?query=a&tracelevel=10");
    Execution execution = new Execution(Execution.Context.createContextStub());
    Result r = new Result(q);
    execution.search(q);
    new Execution(new Chain<>(), execution.context());
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ListenableFuture<Boolean> f = renderer.render(bs, r, execution, null);
    assertTrue(f.get());
    String summary = Utf8.toString(bs.toByteArray());
    ObjectMapper m = new ObjectMapper();
    Map<String, Object> exp = m.readValue(expected, Map.class);
    Map<String, Object> gen = m.readValue(summary, Map.class);
    {
        // nuke timestamp and check it's there
        Map<String, Object> trace = (Map<String, Object>) gen.get("trace");
        List<Object> children1 = (List<Object>) trace.get("children");
        Map<String, Object> subtrace = (Map<String, Object>) children1.get(2);
        List<Object> children2 = (List<Object>) subtrace.get("children");
        Map<String, Object> traceElement = (Map<String, Object>) children2.get(0);
        traceElement.put("timestamp", Integer.valueOf(42));
    }
    assertEquals(exp, gen);
}
Also used : Query(com.yahoo.search.Query) JSONString(com.yahoo.prelude.hitfield.JSONString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) JSONObject(org.json.JSONObject) List(java.util.List) GroupList(com.yahoo.search.grouping.result.GroupList) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 78 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class JsonRendererTestCase method testEmptyTracing.

@Test
public final void testEmptyTracing() throws IOException, InterruptedException, ExecutionException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Query q = new Query("/?query=a&tracelevel=0");
    Execution execution = new Execution(Execution.Context.createContextStub());
    Result r = new Result(q);
    execution.search(q);
    Execution e2 = new Execution(new Chain<Searcher>(), execution.context());
    Query subQuery = new Query("/?query=b&tracelevel=0");
    e2.search(subQuery);
    subQuery.trace("yellow", 1);
    q.trace("marker", 1);
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ListenableFuture<Boolean> f = renderer.render(bs, r, execution, null);
    assertTrue(f.get());
    String summary = Utf8.toString(bs.toByteArray());
    assertEqualJson(expected, summary);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) JSONString(com.yahoo.prelude.hitfield.JSONString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 79 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class JsonRendererTestCase method testTracingOfNestedNodesWithDataAndSubnodes.

@Test
public final void testTracingOfNestedNodesWithDataAndSubnodes() throws IOException, InterruptedException, ExecutionException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    },\n" + "    \"trace\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"message\": \"No query profile is used\"\n" + "            },\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"message\": \"string payload\",\n" + "                        \"children\": [\n" + "                            {\n" + "                                \"children\": [\n" + "                                    {\n" + "                                        \"message\": \"in OO languages, nesting is for birds\"\n" + "                                    }\n" + "                                ]\n" + "                            }\n" + "                        ]\n" + "                    }\n" + "                ]\n" + "            }\n" + "        ]\n" + "    }\n" + "}\n";
    Query q = new Query("/?query=a&tracelevel=1");
    Execution execution = new Execution(Execution.Context.createContextStub());
    Result r = new Result(q);
    execution.search(q);
    final TraceNode child = new TraceNode("string payload", 0L);
    final TraceNode childOfChild = new TraceNode(null, 0L);
    child.add(childOfChild);
    childOfChild.add(new TraceNode("in OO languages, nesting is for birds", 0L));
    execution.trace().traceNode().add(child);
    String summary = render(execution, r);
    assertEqualJson(expected, summary);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) JSONString(com.yahoo.prelude.hitfield.JSONString) TraceNode(com.yahoo.yolean.trace.TraceNode) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 80 with Execution

use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.

the class AsyncGroupPopulationTestCase method test.

@Test
public final void test() throws InterruptedException, ExecutionException, JsonParseException, JsonMappingException, IOException {
    String rawExpected = "{" + "    \"root\": {" + "        \"children\": [" + "            {" + "                \"id\": \"yahoo1\"," + "                \"relevance\": 1.0" + "            }," + "            {" + "                \"id\": \"yahoo2\"," + "                \"relevance\": 1.0" + "            }" + "        ]," + "        \"fields\": {" + "            \"totalCount\": 0" + "        }," + "        \"id\": \"yahoo\"," + "        \"relevance\": 1.0" + "    }" + "}";
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HitGroup h = new InstrumentedGroup("yahoo");
    h.incoming().add(new Hit("yahoo1"));
    JsonRenderer renderer = new JsonRenderer();
    Result result = new Result(new Query(), h);
    renderer.init();
    ListenableFuture<Boolean> f = renderer.render(out, result, new Execution(Execution.Context.createContextStub()), result.getQuery());
    WrappedFuture<DataList<Hit>> x = (WrappedFuture<DataList<Hit>>) h.incoming().completed();
    x.isListening.get(86_400_000);
    h.incoming().add(new Hit("yahoo2"));
    h.incoming().markComplete();
    Boolean b = f.get();
    assertTrue(b);
    String rawGot = Utf8.toString(out.toByteArray());
    ObjectMapper m = new ObjectMapper();
    Map<?, ?> expected = m.readValue(rawExpected, Map.class);
    Map<?, ?> got = m.readValue(rawGot, Map.class);
    assertEquals(expected, got);
}
Also used : Query(com.yahoo.search.Query) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.yahoo.search.Result) DataList(com.yahoo.processing.response.DataList) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Aggregations

Execution (com.yahoo.search.searchchain.Execution)232 Query (com.yahoo.search.Query)184 Result (com.yahoo.search.Result)127 Test (org.junit.Test)123 Searcher (com.yahoo.search.Searcher)88 Chain (com.yahoo.component.chain.Chain)59 IndexFacts (com.yahoo.prelude.IndexFacts)34 Hit (com.yahoo.search.result.Hit)25 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 AndItem (com.yahoo.prelude.query.AndItem)18 WordItem (com.yahoo.prelude.query.WordItem)17 ComponentId (com.yahoo.component.ComponentId)13 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FastHit (com.yahoo.prelude.fastsearch.FastHit)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)13 ArrayList (java.util.ArrayList)12 CompositeItem (com.yahoo.prelude.query.CompositeItem)11