Search in sources :

Example 46 with Hit

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

the class JsonRendererTestCase method testMoreTypes.

@Test
public void testMoreTypes() throws InterruptedException, ExecutionException, IOException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"bigDecimal\": 3.402823669209385e+38,\n" + "                    \"bigInteger\": 340282366920938463463374607431768211455,\n" + "                    \"byte\": 8,\n" + "                    \"short\": 16\n" + "                },\n" + "                \"id\": \"moredatatypestuff\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("moredatatypestuff");
    h.setField("byte", Byte.valueOf((byte) 8));
    h.setField("short", Short.valueOf((short) 16));
    h.setField("bigInteger", new BigInteger("340282366920938463463374607431768211455"));
    h.setField("bigDecimal", new BigDecimal("340282366920938463463374607431768211456.5"));
    h.setField("nanNumber", NanNumber.NaN);
    r.hits().add(h);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) BigInteger(java.math.BigInteger) JSONString(com.yahoo.prelude.hitfield.JSONString) BigDecimal(java.math.BigDecimal) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 47 with Hit

use of com.yahoo.search.result.Hit 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 48 with Hit

use of com.yahoo.search.result.Hit 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 49 with Hit

use of com.yahoo.search.result.Hit 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 50 with Hit

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

Hit (com.yahoo.search.result.Hit)127 Result (com.yahoo.search.Result)72 Query (com.yahoo.search.Query)52 FastHit (com.yahoo.prelude.fastsearch.FastHit)42 Test (org.junit.Test)41 Execution (com.yahoo.search.searchchain.Execution)25 HitGroup (com.yahoo.search.result.HitGroup)21 Searcher (com.yahoo.search.Searcher)17 JSONString (com.yahoo.prelude.hitfield.JSONString)13 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)12 ErrorHit (com.yahoo.search.result.ErrorHit)10 Relevance (com.yahoo.search.result.Relevance)10 HashMap (java.util.HashMap)9 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)8 Group (com.yahoo.search.grouping.result.Group)8 ComponentId (com.yahoo.component.ComponentId)7 Chain (com.yahoo.component.chain.Chain)7 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)6 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)6 GroupList (com.yahoo.search.grouping.result.GroupList)5