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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations