Search in sources :

Example 16 with HitGroup

use of com.yahoo.search.result.HitGroup 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)

Example 17 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class SyncDefaultRendererTestCase method testRenderWriterResult.

@SuppressWarnings("deprecation")
@Test
public final void testRenderWriterResult() throws IOException, InterruptedException, ExecutionException {
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    q.getPresentation().setTiming(true);
    Result r = new Result(q);
    r.setCoverage(new Coverage(500, 1, true));
    TimeTracker t = new TimeTracker(new Chain<Searcher>(new UselessSearcher("first"), new UselessSearcher("second"), new UselessSearcher("third")));
    ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource(new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L }));
    t.sampleSearch(0, true);
    t.sampleSearch(1, true);
    t.sampleSearch(2, true);
    t.sampleSearch(3, true);
    t.sampleSearchReturn(2, true, null);
    t.sampleSearchReturn(1, true, null);
    t.sampleSearchReturn(0, true, null);
    r.getElapsedTime().add(t);
    r.getTemplating().setRenderer(d);
    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"));
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ListenableFuture<Boolean> f = d.render(bs, r, null, null);
    assertTrue(f.get());
    String summary = Utf8.toString(bs.toByteArray());
    // TODO figure out a reasonably strict and reasonably flexible way to test
    assertTrue(summary.length() > 1000);
}
Also used : Query(com.yahoo.search.Query) CreativeTimeSource(com.yahoo.search.statistics.ElapsedTimeTestCase.CreativeTimeSource) Searcher(com.yahoo.search.Searcher) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) Coverage(com.yahoo.search.result.Coverage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.yahoo.search.Result) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) FastHit(com.yahoo.prelude.fastsearch.FastHit) TimeTracker(com.yahoo.search.statistics.TimeTracker) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 18 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitGroupTestCase method testThatHitGroupIsUnFillable.

@Test
public void testThatHitGroupIsUnFillable() {
    HitGroup hg = new HitGroup("test");
    {
        Hit hit = new Hit("http://nalle.balle/1.html", 832);
        hit.setField("url", "http://nalle.balle/1.html");
        hit.setField("clickurl", "javascript:openWindow('http://www.foo');");
        hit.setField("attributes", Arrays.asList("typevideo"));
        hg.add(hit);
    }
    {
        Hit hit = new Hit("http://nalle.balle/2.html", 442);
        hit.setField("url", "http://nalle.balle/2.html");
        hit.setField("clickurl", "");
        hit.setField("attributes", Arrays.asList("typevideo"));
        hg.add(hit);
    }
    assertFalse(hg.isFillable());
    assertTrue(hg.isFilled("anyclass"));
    assertNull(hg.getFilled());
}
Also used : DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) Hit(com.yahoo.search.result.Hit) ErrorHit(com.yahoo.search.result.ErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 19 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitGroupTestCase method testThatHitGroupIsFillable.

@Test
public void testThatHitGroupIsFillable() {
    HitGroup hg = new HitGroup("test");
    {
        Hit hit = new Hit("http://nalle.balle/1.html", 832);
        hit.setField("url", "http://nalle.balle/1.html");
        hit.setField("clickurl", "javascript:openWindow('http://www.foo');");
        hit.setField("attributes", Arrays.asList("typevideo"));
        hit.setFillable();
        hg.add(hit);
    }
    {
        Hit hit = new Hit("http://nalle.balle/2.html", 442);
        hit.setField("url", "http://nalle.balle/2.html");
        hit.setField("clickurl", "");
        hit.setField("attributes", Arrays.asList("typevideo"));
        hit.setFillable();
        hg.add(hit);
    }
    assertTrue(hg.isFillable());
    assertFalse(hg.isFilled("anyclass"));
    assertTrue(hg.getFilled().isEmpty());
}
Also used : DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) Hit(com.yahoo.search.result.Hit) ErrorHit(com.yahoo.search.result.ErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 20 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitGroupTestCase method testThatHitGroupIsFillableAfterFillableChangeunderTheHood.

@Test
public void testThatHitGroupIsFillableAfterFillableChangeunderTheHood() {
    HitGroup hg = new HitGroup("test");
    {
        Hit hit = new Hit("http://nalle.balle/1.html", 832);
        hit.setField("url", "http://nalle.balle/1.html");
        hit.setField("clickurl", "javascript:openWindow('http://www.foo');");
        hit.setField("attributes", Arrays.asList("typevideo"));
        hg.add(hit);
    }
    {
        Hit hit = new Hit("http://nalle.balle/2.html", 442);
        hit.setField("url", "http://nalle.balle/2.html");
        hit.setField("clickurl", "");
        hit.setField("attributes", Arrays.asList("typevideo"));
        hg.add(hit);
    }
    assertFalse(hg.isFillable());
    assertTrue(hg.isFilled("anyclass"));
    for (Hit h : hg.asList()) {
        h.setFillable();
    }
    HitGroup toplevel = new HitGroup("toplevel");
    toplevel.add(hg);
    assertTrue(toplevel.isFillable());
    assertNotNull(toplevel.getFilled());
    assertFalse(toplevel.isFilled("anyclass"));
    assertTrue(hg.isFillable());
    assertNotNull(hg.getFilled());
    assertFalse(hg.isFilled("anyclass"));
    assertTrue(hg.getFilled().isEmpty());
}
Also used : DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) Hit(com.yahoo.search.result.Hit) ErrorHit(com.yahoo.search.result.ErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Aggregations

HitGroup (com.yahoo.search.result.HitGroup)48 Test (org.junit.Test)28 Result (com.yahoo.search.Result)27 Query (com.yahoo.search.Query)24 Hit (com.yahoo.search.result.Hit)21 Execution (com.yahoo.search.searchchain.Execution)11 Searcher (com.yahoo.search.Searcher)8 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)8 Choice (com.yahoo.search.pagetemplates.model.Choice)8 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)7 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)6 Chain (com.yahoo.component.chain.Chain)5 ErrorHit (com.yahoo.search.result.ErrorHit)4 ComponentId (com.yahoo.component.ComponentId)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 FederationSearcher (com.yahoo.search.federation.FederationSearcher)3 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)3 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)3 Coverage (com.yahoo.search.result.Coverage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3