Search in sources :

Example 96 with Hit

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)"));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) IntegerResultNode(com.yahoo.searchlib.expression.IntegerResultNode) GroupList(com.yahoo.search.grouping.result.GroupList) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 97 with Hit

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());
}
Also used : Chain(com.yahoo.component.chain.Chain) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 98 with Hit

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);
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) DocumentId(com.yahoo.document.DocumentId) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 99 with Hit

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);
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 100 with Hit

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);
}
Also used : Hit(com.yahoo.search.result.Hit) Parameters(com.yahoo.search.statistics.TimingSearcher.Parameters) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Ping(com.yahoo.prelude.Ping) ComponentId(com.yahoo.component.ComponentId) Result(com.yahoo.search.Result)

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