Search in sources :

Example 11 with HitGroup

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

the class FederationSearcherTest method require_that_hits_can_be_filled_when_moved.

@Test
public void require_that_hits_can_be_filled_when_moved() {
    FederationTester tester = new FederationTester();
    tester.addSearchChain("chain1", new AddHitSearcher());
    tester.addSearchChain("chain2", new AddHitSearcher());
    Result result = tester.search();
    Result reorganizedResult = new Result(result.getQuery());
    HitGroup hit1 = new HitGroup();
    HitGroup nestedHitGroup = new HitGroup();
    hit1.add(nestedHitGroup);
    reorganizedResult.hits().add(hit1);
    HitGroup chain1Group = (HitGroup) result.hits().get(0);
    HitGroup chain2Group = (HitGroup) result.hits().get(1);
    nestedHitGroup.add(chain1Group.get(0));
    reorganizedResult.hits().add(chain2Group.get(0));
    reorganizedResult.hits().add(nestedHitGroup);
    tester.fill(reorganizedResult);
    assertFilled(nestedHitGroup.get(0));
    assertFilled(chain2Group.get(0));
}
Also used : Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 12 with HitGroup

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

the class DocumentXMLTemplate method header.

@Override
public void header(Context context, Writer writer) throws IOException {
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    writer.write("<result>\n");
    HitGroup rootGroup = ((Result) context.get("result")).hits();
    if (rootGroup.getField(VisitSearcher.VISITOR_CONTINUATION_TOKEN_FIELDNAME) != null) {
        writer.write("<continuation>" + rootGroup.getField(VisitSearcher.VISITOR_CONTINUATION_TOKEN_FIELDNAME) + "</continuation>");
    }
}
Also used : HitGroup(com.yahoo.search.result.HitGroup) Result(com.yahoo.search.Result)

Example 13 with HitGroup

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

the class GetSearcherTestCase method testQueryPassThroughAndGetUnknownBackendHit.

@Test
public void testQueryPassThroughAndGetUnknownBackendHit() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    HitGroup hits = new HitGroup("mock");
    hits.add(new Hit("blernsball"));
    Chain<Searcher> searchChain = new Chain<>(searcher, new MockBackend(hits));
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?flarn=blern&id=userdoc:kittens:9:aaa"));
    assertEquals(0, factory.messages.size());
    assertNotNull(result.hits().getErrorHit());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"18\" message=\"Internal server error.: " + "A backend searcher to com.yahoo.storage.searcher.GetSearcher returned a " + "hit that was not an instance of com.yahoo.storage.searcher.DocumentHit. " + "Only DocumentHit instances are supported in the backend hit result set " + "when doing queries that contain document identifier sets recognised by the " + "Get Searcher.\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 14 with HitGroup

use of com.yahoo.search.result.HitGroup 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());
}
Also used : Chain(com.yahoo.component.chain.Chain) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) Result(com.yahoo.search.Result) FederationOptions(com.yahoo.search.searchchain.model.federation.FederationOptions) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) ComponentId(com.yahoo.component.ComponentId) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 15 with HitGroup

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

the class JsonRendererTestCase method test.

@Test
public final void test() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"fields\": {\n" + "                            \"c\": \"d\",\n" + "                            \"uri\": \"http://localhost/1\"\n" + "                        },\n" + "                        \"id\": \"http://localhost/1\",\n" + "                        \"relevance\": 0.9,\n" + "                        \"types\": [\n" + "                            \"summary\"\n" + "                        ]\n" + "                    }\n" + "                ],\n" + "                \"id\": \"usual\",\n" + "                \"relevance\": 1.0\n" + "            },\n" + "            {\n" + "                \"fields\": {\n" + "                    \"e\": \"f\"\n" + "                },\n" + "                \"id\": \"type grouphit\",\n" + "                \"relevance\": 1.0,\n" + "                \"types\": [\n" + "                    \"grouphit\"\n" + "                ]\n" + "            },\n" + "            {\n" + "                \"fields\": {\n" + "                    \"b\": \"foo\",\n" + "                    \"uri\": \"http://localhost/\"\n" + "                },\n" + "                \"id\": \"http://localhost/\",\n" + "                \"relevance\": 0.95,\n" + "                \"types\": [\n" + "                    \"summary\"\n" + "                ]\n" + "            }\n" + "        ],\n" + "        \"coverage\": {\n" + "            \"coverage\": 100,\n" + "            \"documents\": 500,\n" + "            \"full\": true,\n" + "            \"nodes\": 1,\n" + "            \"results\": 1,\n" + "            \"resultsFull\": 1\n" + "        },\n" + "        \"errors\": [\n" + "            {\n" + "                \"code\": 18,\n" + "                \"message\": \"boom\",\n" + "                \"summary\": \"Internal server error.\"\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}";
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    Execution execution = new Execution(Execution.Context.createContextStub());
    Result r = new Result(q);
    r.setCoverage(new Coverage(500, 1, true));
    FastHit h = new FastHit("http://localhost/", .95);
    h.setField("$a", "Hello, world.");
    h.setField("b", "foo");
    r.hits().add(h);
    HitGroup g = new HitGroup("usual");
    h = new FastHit("http://localhost/1", .90);
    h.setField("c", "d");
    g.add(h);
    r.hits().add(g);
    HitGroup gg = new HitGroup("type grouphit");
    gg.types().add("grouphit");
    gg.setField("e", "f");
    r.hits().add(gg);
    r.hits().addError(ErrorMessage.createInternalServerError("boom"));
    String summary = render(execution, r);
    assertEqualJson(expected, summary);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) Coverage(com.yahoo.search.result.Coverage) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Aggregations

HitGroup (com.yahoo.search.result.HitGroup)48 Test (org.junit.Test)28 Result (com.yahoo.search.Result)27 Query (com.yahoo.search.Query)24 Hit (com.yahoo.search.result.Hit)21 Execution (com.yahoo.search.searchchain.Execution)11 Searcher (com.yahoo.search.Searcher)8 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)8 Choice (com.yahoo.search.pagetemplates.model.Choice)8 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)7 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)6 Chain (com.yahoo.component.chain.Chain)5 ErrorHit (com.yahoo.search.result.ErrorHit)4 ComponentId (com.yahoo.component.ComponentId)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 FederationSearcher (com.yahoo.search.federation.FederationSearcher)3 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)3 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)3 Coverage (com.yahoo.search.result.Coverage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3