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());
}
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();
}
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);
}
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);
}
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);
}
Aggregations