use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class FutureDataTestCase method testAsyncFederation.
@Test
public void testAsyncFederation() throws InterruptedException, ExecutionException, TimeoutException {
// Setup environment
AsyncProviderSearcher asyncProviderSearcher = new AsyncProviderSearcher();
Searcher syncProviderSearcher = new SyncProviderSearcher();
Chain<Searcher> asyncSource = new Chain<Searcher>(new ComponentId("async"), asyncProviderSearcher);
Chain<Searcher> syncSource = new Chain<>(new ComponentId("sync"), syncProviderSearcher);
SearchChainResolver searchChainResolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("sync"), new FederationOptions().setUseByDefault(true)).addSearchChain(new ComponentId("async"), new FederationOptions().setUseByDefault(true)).build();
Chain<Searcher> main = new Chain<Searcher>(new FederationSearcher(new ComponentId("federator"), searchChainResolver));
SearchChainRegistry searchChainRegistry = new SearchChainRegistry();
searchChainRegistry.register(main);
searchChainRegistry.register(syncSource);
searchChainRegistry.register(asyncSource);
Result result = new Execution(main, Execution.Context.createContextStub(searchChainRegistry, null)).search(new Query());
assertNotNull(result);
HitGroup syncGroup = (HitGroup) result.hits().get("source:sync");
assertNotNull(syncGroup);
HitGroup asyncGroup = (HitGroup) result.hits().get("source:async");
assertNotNull(asyncGroup);
assertEquals("Got all sync data", 3, syncGroup.size());
assertEquals("sync:0", syncGroup.get(0).getId().toString());
assertEquals("sync:1", syncGroup.get(1).getId().toString());
assertEquals("sync:2", syncGroup.get(2).getId().toString());
assertTrue(asyncGroup.incoming() == asyncProviderSearcher.incomingData);
assertEquals("Got no async data yet", 0, asyncGroup.size());
asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:0"));
assertEquals("Got no async data yet, as we haven't completed the incoming buffer and there is no data listener", 0, asyncGroup.size());
asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:1"));
asyncProviderSearcher.simulateAllHitsIOComplete();
assertEquals("Got no async data yet, as we haven't pulled it", 0, asyncGroup.size());
asyncGroup.complete().get();
assertEquals("Completed, so we have the data", 2, asyncGroup.size());
assertEquals("async:0", asyncGroup.get(0).getId().toString());
assertEquals("async:1", asyncGroup.get(1).getId().toString());
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JsonRendererTestCase method testJsonObjects.
@Test
public void testJsonObjects() throws InterruptedException, ExecutionException, IOException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"inspectable\": {\n" + " \"a\": \"b\"\n" + " },\n" + " \"jackson\": {\n" + " \"Nineteen-eighty-four\": 1984\n" + " },\n" + " \"json producer\": {\n" + " \"long in structured\": 7809531904\n" + " },\n" + " \"org.json array\": [\n" + " true,\n" + " true,\n" + " false\n" + " ],\n" + " \"org.json object\": {\n" + " \"forty-two\": 42\n" + " }\n" + " },\n" + " \"id\": \"json objects\",\n" + " \"relevance\": 1.0\n" + " }\n" + " ],\n" + " \"fields\": {\n" + " \"totalCount\": 0\n" + " },\n" + " \"id\": \"toplevel\",\n" + " \"relevance\": 1.0\n" + " }\n" + "}\n";
Result r = newEmptyResult();
Hit h = new Hit("json objects");
JSONObject o = new JSONObject();
JSONArray a = new JSONArray();
ObjectMapper mapper = new ObjectMapper();
JsonNode j = mapper.createObjectNode();
JSONString s = new JSONString("{\"a\": \"b\"}");
Slime slime = new Slime();
Cursor c = slime.setObject();
c.setLong("long in structured", 7809531904L);
SlimeAdapter slimeInit = new SlimeAdapter(slime.get());
StructuredData struct = new StructuredData(slimeInit);
((ObjectNode) j).put("Nineteen-eighty-four", 1984);
o.put("forty-two", 42);
a.put(true);
a.put(true);
a.put(false);
h.setField("inspectable", s);
h.setField("jackson", j);
h.setField("json producer", struct);
h.setField("org.json array", a);
h.setField("org.json object", o);
r.hits().add(h);
String summary = render(r);
assertEqualJson(expected, summary);
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JsonRendererTestCase method testDocumentId.
@Test
public void testDocumentId() throws IOException, InterruptedException, ExecutionException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"documentid\": \"id:unittest:smoke::whee\"\n" + " },\n" + " \"id\": \"id:unittest:smoke::whee\",\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("docIdTest");
h.setField("documentid", new DocumentId("id:unittest:smoke::whee"));
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 JsonRendererTestCase method createHitWithOnlyHiddenFields.
private Hit createHitWithOnlyHiddenFields() {
Hit h = new Hit("hiddenFields");
h.setField("NaN", NanNumber.NaN);
h.setField("emptyString", "");
h.setField("emptyStringFieldValue", new StringFieldValue(""));
h.setField("$vespaImplementationDetail", "Hello, World!");
return h;
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JsonRendererTestCase method testDataTypes.
@Test
public void testDataTypes() throws IOException, InterruptedException, ExecutionException, JSONException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"double\": 0.00390625,\n" + " \"float\": 14.29,\n" + " \"integer\": 1,\n" + " \"long\": 4398046511104,\n" + " \"object\": \"thingie\",\n" + " \"string\": \"stuff\",\n" + " \"predicate\": \"a in [b]\",\n" + " \"tensor1\": { \"cells\": [ { \"address\": {\"x\": \"a\"}, \"value\":2.0 } ] },\n" + " \"tensor2\": { \"cells\": [] },\n" + " \"tensor3\": { \"cells\": [ { \"address\": {\"x\": \"a\", \"y\": \"0\"}, \"value\":2.0 }, { \"address\": {\"x\": \"a\", \"y\": \"1\"}, \"value\":-1.0 } ] }\n" + " },\n" + " \"id\": \"datatypestuff\",\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("datatypestuff");
// the floating point values are chosen to get a deterministic string representation
h.setField("double", 0.00390625d);
h.setField("float", 14.29f);
h.setField("integer", 1);
h.setField("long", 4398046511104L);
h.setField("string", "stuff");
h.setField("predicate", Predicate.fromString("a in [b]"));
h.setField("tensor1", new TensorFieldValue(Tensor.from("{ {x:a}: 2.0}")));
h.setField("tensor2", new TensorFieldValue(TensorType.empty));
h.setField("tensor3", Tensor.from("{ {x:a, y:0}: 2.0, {x:a, y:1}: -1 }"));
h.setField("object", new Thingie());
r.hits().add(h);
r.setTotalHitCount(1L);
String summary = render(r);
assertEqualJson(expected, summary);
}
Aggregations