Search in sources :

Example 1 with FederationSearcher

use of com.yahoo.search.federation.FederationSearcher in project vespa by vespa-engine.

the class FederationSearcherTestCase method twoTracingSources.

private Chain<Searcher> twoTracingSources(boolean strictContracts) {
    addChained(new Searcher() {

        @Override
        public Result search(Query query, Execution execution) {
            query.trace(SOURCE1, 1);
            return execution.search(query);
        }
    }, SOURCE1);
    addChained(new Searcher() {

        @Override
        public Result search(Query query, Execution execution) {
            query.trace(SOURCE2, 1);
            return execution.search(query);
        }
    }, SOURCE2);
    Chain<Searcher> mainChain = new Chain<>("default", new FederationSearcher(new FederationConfig(builder), new StrictContractsConfig(new StrictContractsConfig.Builder().searchchains(strictContracts)), new ComponentRegistry<>()));
    return mainChain;
}
Also used : StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) Chain(com.yahoo.component.chain.Chain) SearchChain(com.yahoo.search.searchchain.SearchChain) Execution(com.yahoo.search.searchchain.Execution) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) FederationConfig(com.yahoo.search.federation.FederationConfig) Result(com.yahoo.search.Result)

Example 2 with FederationSearcher

use of com.yahoo.search.federation.FederationSearcher 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 3 with FederationSearcher

use of com.yahoo.search.federation.FederationSearcher in project vespa by vespa-engine.

the class DuplicateSourceTestCase method testDuplicateSource.

@Test
public void testDuplicateSource() {
    // Set up a single cluster and chain (chain1), containing a MockBackendSearcher and having 2 doc types (doc1, doc2)
    MockBackendSearcher mockBackendSearcher = new MockBackendSearcher();
    SearchChainRegistry searchChains = new SearchChainRegistry();
    searchChains.register(new Chain<>("chain1", mockBackendSearcher));
    IndexFacts indexFacts = new IndexFacts();
    Map<String, List<String>> clusters = new HashMap<>();
    clusters.put("chain1", ImmutableList.of("doc1", "doc2"));
    indexFacts.setClusters(clusters);
    SearchChainResolver resolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("chain1"), ImmutableList.of("doc1", "doc2")).build();
    FederationSearcher searcher = new FederationSearcher(new ComponentId("test"), resolver);
    Result result = searcher.search(new Query("?query=test&sources=doc1%2cdoc2"), new Execution(Execution.Context.createContextStub(searchChains, indexFacts)));
    assertNull(result.hits().getError());
    assertEquals(1, mockBackendSearcher.getInvocationCount());
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 4 with FederationSearcher

use of com.yahoo.search.federation.FederationSearcher in project vespa by vespa-engine.

the class FederationSearcherTestCase method createMultiProviderFederationSearcher.

private FederationSearcher createMultiProviderFederationSearcher() {
    FederationOptions options = new FederationOptions();
    SearchChainResolver.Builder builder = new SearchChainResolver.Builder();
    ComponentId provider1 = new ComponentId("provider1");
    ComponentId provider2 = new ComponentId("provider2");
    ComponentId news = new ComponentId("news");
    builder.addSearchChain(provider1, options, Collections.<String>emptyList());
    builder.addSearchChain(provider2, options, Collections.<String>emptyList());
    builder.addSourceForProvider(news, provider1, provider1, true, options, Collections.<String>emptyList());
    builder.addSourceForProvider(news, provider2, provider2, false, options, Collections.<String>emptyList());
    return new FederationSearcher(new ComponentId("federation"), builder.build());
}
Also used : FederationOptions(com.yahoo.search.searchchain.model.federation.FederationOptions) FederationSearcher(com.yahoo.search.federation.FederationSearcher) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) ComponentId(com.yahoo.component.ComponentId)

Example 5 with FederationSearcher

use of com.yahoo.search.federation.FederationSearcher in project vespa by vespa-engine.

the class FederationSearcherTest method custom_federation_target.

@Test
public void custom_federation_target() {
    ComponentId targetSelectorId = ComponentId.fromString("TargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestTargetSelector());
    FederationSearcher searcher = new FederationSearcher(new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())), new StrictContractsConfig(new StrictContractsConfig.Builder()), targetSelectors);
    Result result = new Execution(searcher, Context.createContextStub()).search(new Query());
    HitGroup myChainGroup = (HitGroup) result.hits().get(0);
    assertThat(myChainGroup.getId(), is(new URI("source:myChain")));
    assertThat(myChainGroup.get(0).getId(), is(new URI("myHit")));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) URI(com.yahoo.net.URI) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) Execution(com.yahoo.search.searchchain.Execution) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) TargetSelector(com.yahoo.search.federation.selection.TargetSelector) ComponentId(com.yahoo.component.ComponentId) FederationConfig(com.yahoo.search.federation.FederationConfig) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Aggregations

FederationSearcher (com.yahoo.search.federation.FederationSearcher)6 ComponentId (com.yahoo.component.ComponentId)5 Query (com.yahoo.search.Query)5 Result (com.yahoo.search.Result)5 Execution (com.yahoo.search.searchchain.Execution)5 Test (org.junit.Test)4 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)3 FederationConfig (com.yahoo.search.federation.FederationConfig)3 StrictContractsConfig (com.yahoo.search.federation.StrictContractsConfig)3 SearchChainResolver (com.yahoo.search.federation.sourceref.SearchChainResolver)3 Chain (com.yahoo.component.chain.Chain)2 Searcher (com.yahoo.search.Searcher)2 TargetSelector (com.yahoo.search.federation.selection.TargetSelector)2 Hit (com.yahoo.search.result.Hit)2 HitGroup (com.yahoo.search.result.HitGroup)2 SearchChainRegistry (com.yahoo.search.searchchain.SearchChainRegistry)2 FederationOptions (com.yahoo.search.searchchain.model.federation.FederationOptions)2 ImmutableList (com.google.common.collect.ImmutableList)1 URI (com.yahoo.net.URI)1 IndexFacts (com.yahoo.prelude.IndexFacts)1