Search in sources :

Example 6 with SearchChainRegistry

use of com.yahoo.search.searchchain.SearchChainRegistry 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 7 with SearchChainRegistry

use of com.yahoo.search.searchchain.SearchChainRegistry in project vespa by vespa-engine.

the class FederationSearcherTestCase method setUp.

@Before
public void setUp() throws Exception {
    builder = new FederationConfig.Builder();
    chainRegistry = new SearchChainRegistry();
}
Also used : SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) FederationConfig(com.yahoo.search.federation.FederationConfig) Before(org.junit.Before)

Example 8 with SearchChainRegistry

use of com.yahoo.search.searchchain.SearchChainRegistry in project vespa by vespa-engine.

the class FederationSearcherTestCase method testProviderSelectionFromQueryProperties.

@Test
public void testProviderSelectionFromQueryProperties() {
    SearchChainRegistry registry = new SearchChainRegistry();
    registry.register(new Chain<>("provider1", new MockProvider("provider1")));
    registry.register(new Chain<>("provider2", new MockProvider("provider2")));
    registry.register(new Chain<>("default", createMultiProviderFederationSearcher()));
    assertSelects("provider1", registry);
    assertSelects("provider2", registry);
}
Also used : SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) Test(org.junit.Test)

Example 9 with SearchChainRegistry

use of com.yahoo.search.searchchain.SearchChainRegistry in project vespa by vespa-engine.

the class SearchChainConfigurerTestCase method testChainsConfigUpdate.

/**
 * Updates the chains config, while the searcher configs are unchanged.
 * Verifies that a new searcher that was not in the old config is instantiated,
 * and that a searcher that has been removed from the configuration is not in the new registry.
 */
@Test
public void testChainsConfigUpdate() throws IOException, InterruptedException {
    File cfgDir = getCfgDir();
    copyFile(testDir + "handlers.cfg", cfgDir + "/handlers.cfg");
    copyFile(testDir + "qr-search.cfg", cfgDir + "/qr-search.cfg");
    copyFile(testDir + "qr-searchers.cfg", cfgDir + "/qr-searchers.cfg");
    copyFile(testDir + "index-info.cfg", cfgDir + "/index-info.cfg");
    copyFile(testDir + "specialtokens.cfg", cfgDir + "/specialtokens.cfg");
    copyFile(testDir + "chainsConfigUpdate_1.cfg", cfgDir + "/chains.cfg");
    copyFile(testDir + "container-http.cfg", cfgDir + "/container-http.cfg");
    createComponentsConfig(testDir + "chainsConfigUpdate_1.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper("dir:" + cfgDir);
    SearchChainRegistry scReg = getSearchChainRegistryFrom(configurer);
    SearcherRegistry searchers = scReg.getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(2));
    assertThat(searchers.getComponent(IntSearcher.class.getName()), instanceOf(IntSearcher.class));
    assertThat(searchers.getComponent(StringSearcher.class.getName()), instanceOf(StringSearcher.class));
    assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), nullValue());
    assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), nullValue());
    IntSearcher intSearcher = (IntSearcher) searchers.getComponent(IntSearcher.class.getName());
    // Update chains config
    copyFile(testDir + "chainsConfigUpdate_2.cfg", cfgDir + "/chains.cfg");
    createComponentsConfig(testDir + "chainsConfigUpdate_2.cfg", testDir + "handlers.cfg", cfgDir + "/components.cfg");
    configurer.reloadConfig();
    assertThat(getSearchChainRegistryFrom(configurer), not(scReg));
    // In the new registry, the correct searchers are removed and added
    assertThat(getSearchChainRegistryFrom(configurer).getSearcherRegistry(), not(searchers));
    searchers = getSearchChainRegistryFrom(configurer).getSearcherRegistry();
    assertThat(searchers.getComponentCount(), is(3));
    assertThat((IntSearcher) searchers.getComponent(IntSearcher.class.getName()), sameInstance(intSearcher));
    assertThat(searchers.getComponent(ConfigurableSearcher.class.getName()), instanceOf(ConfigurableSearcher.class));
    assertThat(searchers.getComponent(DeclaredTestSearcher.class.getName()), instanceOf(DeclaredTestSearcher.class));
    assertThat(searchers.getComponent(StringSearcher.class.getName()), nullValue());
    configurer.shutdown();
    cleanup(cfgDir);
}
Also used : SearcherRegistry(com.yahoo.search.searchchain.SearcherRegistry) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) Test(org.junit.Test)

Example 10 with SearchChainRegistry

use of com.yahoo.search.searchchain.SearchChainRegistry in project vespa by vespa-engine.

the class SearchChainDispatcherSearcherTestCase method setUp.

/**
 * Load the QueryRewriteSearcher and prepare the
 * execution object
 */
@SuppressWarnings("deprecation")
protected void setUp() {
    // Instantiate Name Rewriter
    RewritesConfig config = QueryRewriteSearcherTestUtils.createConfigObj(NAME_REWRITER_CONFIG_PATH);
    HashMap<String, File> fileList = new HashMap<>();
    fileList.put(NameRewriter.NAME_ENTITY_EXPAND_DICT, new File(NAME_ENTITY_EXPAND_DICT_PATH));
    NameRewriter nameRewriter = new NameRewriter(config, fileList);
    // Instantiate Misspell Rewriter
    MisspellRewriter misspellRewriter = new MisspellRewriter();
    // Create market search chain of two rewriters
    ArrayList<Searcher> searchers = new ArrayList<>();
    searchers.add(misspellRewriter);
    searchers.add(nameRewriter);
    Chain<Searcher> marketSearchChain = new Chain<>(US_MARKET_SEARCH_CHAIN, searchers);
    // Add market search chain to the registry
    SearchChainRegistry registry = new SearchChainRegistry();
    registry.register(marketSearchChain);
    // Instantiate Search Chain Dispatcher Searcher
    SearchChainDispatcherSearcher searchChainDispatcher = new SearchChainDispatcherSearcher();
    // Create a chain containing only the dispatcher
    Chain<Searcher> mainSearchChain = new Chain<>(searchChainDispatcher);
    Execution execution = new Execution(mainSearchChain, Execution.Context.createContextStub(registry, null));
    utils = new QueryRewriteSearcherTestUtils(execution);
}
Also used : Chain(com.yahoo.component.chain.Chain) RewritesConfig(com.yahoo.search.query.rewrite.RewritesConfig) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) File(java.io.File)

Aggregations

SearchChainRegistry (com.yahoo.search.searchchain.SearchChainRegistry)10 Test (org.junit.Test)4 Chain (com.yahoo.component.chain.Chain)3 ComponentId (com.yahoo.component.ComponentId)2 Query (com.yahoo.search.Query)2 Result (com.yahoo.search.Result)2 Searcher (com.yahoo.search.Searcher)2 FederationSearcher (com.yahoo.search.federation.FederationSearcher)2 SearchChainResolver (com.yahoo.search.federation.sourceref.SearchChainResolver)2 RewritesConfig (com.yahoo.search.query.rewrite.RewritesConfig)2 Execution (com.yahoo.search.searchchain.Execution)2 File (java.io.File)2 ImmutableList (com.google.common.collect.ImmutableList)1 HandlersConfigurerTestWrapper (com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper)1 StringValue (com.yahoo.jrt.StringValue)1 IndexFacts (com.yahoo.prelude.IndexFacts)1 ClusterSearcher (com.yahoo.prelude.cluster.ClusterSearcher)1 SearchChainTextRepresentation (com.yahoo.search.debug.SearchChainTextRepresentation)1 FederationConfig (com.yahoo.search.federation.FederationConfig)1 SearchHandler (com.yahoo.search.handler.SearchHandler)1