use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatPassResultsAreMerged.
@Test
public void requireThatPassResultsAreMerged() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(min(bar), max(bar))))"));
Grouping grpA = new Grouping(0);
grpA.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueA")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(6)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))));
Grouping grpB = new Grouping(0);
grpB.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueB")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MinAggregationResult().setMin(new IntegerResultNode(6)).setTag(3))));
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpA), null), new GroupingListHit(Arrays.asList(grpB), null))));
Group grp = req.getResultGroup(exec.search(query));
assertEquals(1, grp.size());
Hit hit = grp.get(0);
assertTrue(hit instanceof GroupList);
GroupList lst = (GroupList) hit;
assertEquals(3, lst.size());
assertNotNull(hit = lst.get("group:string:uniqueA"));
assertEquals(6L, hit.getField("max(bar)"));
assertNotNull(hit = lst.get("group:string:uniqueB"));
assertEquals(9L, hit.getField("max(bar)"));
assertNotNull(hit = lst.get("group:string:common"));
assertEquals(6L, hit.getField("min(bar)"));
assertEquals(9L, hit.getField("max(bar)"));
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class FutureDataTestCase method testFutureData.
@Test
public void testFutureData() throws InterruptedException, ExecutionException, TimeoutException {
// Set up
AsyncProviderSearcher futureDataSource = new AsyncProviderSearcher();
Chain<Searcher> chain = new Chain<>(Collections.<Searcher>singletonList(futureDataSource));
// Execute
Query query = new Query();
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
// Verify the result prior to completion of delayed data
assertEquals("The result has been returned, but no hits are available yet", 0, result.hits().getConcreteSize());
// pretend we're the IO layer and complete delayed data - this is typically done in a callback from jDisc
futureDataSource.simulateOneHitIOComplete(new Hit("hit:0"));
futureDataSource.simulateOneHitIOComplete(new Hit("hit:1"));
futureDataSource.simulateAllHitsIOComplete();
assertEquals("Async arriving hits are still not visible because we haven't asked for them", 0, result.hits().getConcreteSize());
// Results with future hit groups will be passed to rendering directly and start rendering immediately.
// For this test we block and wait for the data instead:
result.hits().complete().get(1000, TimeUnit.MILLISECONDS);
assertEquals(2, result.hits().getConcreteSize());
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JsonRendererTestCase method testJsonCallback.
@Test
public final void testJsonCallback() 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";
String jsonCallback = "some_function_name";
Result r = newEmptyResult(new String[] { "query=a", "jsoncallback=" + jsonCallback });
Hit h = new Hit("jsonCallbackTest");
h.setField("documentid", new DocumentId("id:unittest:smoke::whee"));
r.hits().add(h);
r.setTotalHitCount(1L);
String summary = render(r);
String jsonCallbackBegin = summary.substring(0, jsonCallback.length() + 1);
String jsonCallbackEnd = summary.substring(summary.length() - 2);
String json = summary.substring(jsonCallback.length() + 1, summary.length() - 2);
assertEquals(jsonCallback + "(", jsonCallbackBegin);
assertEqualJson(expected, json);
assertEquals(");", jsonCallbackEnd);
}
use of com.yahoo.search.result.Hit in project vespa by vespa-engine.
the class JsonRendererTestCase method testNullField.
@Test
public void testNullField() throws InterruptedException, ExecutionException, IOException {
String expected = "{\n" + " \"root\": {\n" + " \"children\": [\n" + " {\n" + " \"fields\": {\n" + " \"null\": null\n" + " },\n" + " \"id\": \"nullstuff\",\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("nullstuff");
h.setField("null", null);
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 TimingSearcherTestCase method testMeasurementPingPath.
public void testMeasurementPingPath() {
Parameters p = new Parameters("timingtest", TimeTracker.Activity.PING);
TimingSearcher ts = new TimingSearcher(new ComponentId("lblblbl"), p, Statistics.nullImplementation);
MockValue v = new MockValue();
ts.setMeasurements(v);
Execution exec = new Execution(ts, Execution.Context.createContextStub());
Result r = exec.search(new Query("/?query=a"));
Hit f = new Hit("blblbl");
f.setFillable();
r.hits().add(f);
exec.fill(r, "whatever");
exec.fill(r, "lalala");
exec.ping(new Ping());
exec.ping(new Ping());
exec.ping(new Ping());
assertEquals(3, v.putCount);
}
Aggregations