Search in sources :

Example 1 with FederationConfig

use of com.yahoo.search.federation.FederationConfig 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 FederationConfig

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

the class DomFederationSearcherBuilderTest method require_that_target_selector_can_be_configured.

@Test
public void require_that_target_selector_can_be_configured() {
    FederationSearcher searcher = new DomFederationSearcherBuilder().doBuild(root, parse("<federation id='federation-id'>", "    <target-selector id='my-id' class='my-class' />", "</federation>"));
    String targetSelectorId = "my-id@federation-id";
    AbstractConfigProducer<?> targetSelector = searcher.getChildren().get(targetSelectorId);
    assertNotNull("No target selector child found", targetSelector);
    FederationConfig.Builder builder = new FederationConfig.Builder();
    searcher.getConfig(builder);
    assertThat(new FederationConfig(builder).targetSelector(), is(targetSelectorId));
}
Also used : FederationSearcher(com.yahoo.vespa.model.container.search.searchchain.FederationSearcher) FederationConfig(com.yahoo.search.federation.FederationConfig) Test(org.junit.Test) DomBuilderTest(com.yahoo.config.model.builder.xml.test.DomBuilderTest)

Example 3 with FederationConfig

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

the class FederationTest method validateNativeDefaultTargets.

@Test
public void validateNativeDefaultTargets() {
    FederationConfig.Builder fb = new FederationConfig.Builder();
    root.getConfig(fb, "searchchains/chain/native/component/federation");
    FederationConfig config = new FederationConfig(fb);
    for (FederationConfig.Target target : config.target()) {
        String failMessage = "Failed for target " + target.id();
        if (target.id().startsWith("source")) {
            assertTrue(failMessage, target.useByDefault());
        } else {
            assertFalse(failMessage, target.useByDefault());
        }
    }
    assertThat(config.target().size(), is(5));
    assertUseByDefault(config, "source1", false);
    assertUseByDefault(config, "source2", false);
    assertUseByDefault(config, "provider2", true);
    assertUseByDefault(config, "cluster2", true);
    assertUseByDefault(config, "sourceCommon", "provider1", false);
    assertUseByDefault(config, "sourceCommon", "provider3", false);
}
Also used : FederationConfig(com.yahoo.search.federation.FederationConfig) Test(org.junit.Test)

Example 4 with FederationConfig

use of com.yahoo.search.federation.FederationConfig 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)

Example 5 with FederationConfig

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

the class FederationSearcherTest method target_selectors_can_have_multiple_targets.

@Test
public void target_selectors_can_have_multiple_targets() {
    ComponentId targetSelectorId = ComponentId.fromString("TestMultipleTargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestMultipleTargetSelector());
    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());
    Iterator<Hit> hitsIterator = result.hits().deepIterator();
    Hit hit1 = hitsIterator.next();
    Hit hit2 = hitsIterator.next();
    assertThat(hit1.getSource(), is("chain1"));
    assertThat(hit2.getSource(), is("chain2"));
    assertThat((String) hit1.getField("data"), is("modifyTargetQuery:custom-data:1"));
    assertThat((String) hit2.getField("data"), is("modifyTargetQuery:custom-data:2"));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) 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) Test(org.junit.Test)

Aggregations

FederationConfig (com.yahoo.search.federation.FederationConfig)5 Test (org.junit.Test)4 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)3 Query (com.yahoo.search.Query)3 Result (com.yahoo.search.Result)3 FederationSearcher (com.yahoo.search.federation.FederationSearcher)3 StrictContractsConfig (com.yahoo.search.federation.StrictContractsConfig)3 Execution (com.yahoo.search.searchchain.Execution)3 ComponentId (com.yahoo.component.ComponentId)2 TargetSelector (com.yahoo.search.federation.selection.TargetSelector)2 Chain (com.yahoo.component.chain.Chain)1 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)1 URI (com.yahoo.net.URI)1 Searcher (com.yahoo.search.Searcher)1 ErrorHit (com.yahoo.search.result.ErrorHit)1 Hit (com.yahoo.search.result.Hit)1 HitGroup (com.yahoo.search.result.HitGroup)1 SearchChain (com.yahoo.search.searchchain.SearchChain)1 FederationSearcher (com.yahoo.vespa.model.container.search.searchchain.FederationSearcher)1