Search in sources :

Example 1 with SearchChainRegistry

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

the class SearchChainTextRepresentationTestCase method testTextRepresentation.

public void testTextRepresentation() {
    SearchChainTextRepresentation textRepresentation = new SearchChainTextRepresentation(SimpleSearchChain.orderedChain, new SearchChainRegistry());
    String[] expected = { "test [Searchchain]  {", "  one [Searcher] {", "    Reason for forwarding to this search chain.", "    child-chain [Searchchain]  {", "      child-searcher [Searcher]", "    }", "    child-chain [Searchchain]  {", "      child-searcher [Searcher]", "    }", "  }", "  two [Searcher] {", "    Reason for forwarding to this search chain.", "    child-chain [Searchchain]  {", "      child-searcher [Searcher]", "    }", "    child-chain [Searchchain]  {", "      child-searcher [Searcher]", "    }", "  }", "}" };
    String[] result = textRepresentation.toString().split("\n");
    assertEquals(expected.length, result.length);
    int i = 0;
    for (String line : textRepresentation.toString().split("\n")) assertEquals(expected[i++], line);
}
Also used : SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) SearchChainTextRepresentation(com.yahoo.search.debug.SearchChainTextRepresentation)

Example 2 with SearchChainRegistry

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

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

the class SearchChainDispatcherSearcherTestCase method testChainContinuation.

/**
 * Searchers down the chain after SearchChainDispatcher
 * should be executed
 */
@SuppressWarnings("deprecation")
public void testChainContinuation() {
    // 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 only misspell rewriter
    Chain<Searcher> marketSearchChain = new Chain<>(US_MARKET_SEARCH_CHAIN, misspellRewriter);
    // 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 the dispatcher and the name rewriter
    ArrayList<Searcher> searchers = new ArrayList<>();
    searchers.add(searchChainDispatcher);
    searchers.add(nameRewriter);
    // Create a chain containing only the dispatcher
    Chain<Searcher> mainSearchChain = new Chain<>(searchers);
    Execution execution = new Execution(mainSearchChain, Execution.Context.createContextStub(registry, null));
    new QueryRewriteSearcherTestUtils(execution);
    IntentModel intentModel = new IntentModel(utils.createInterpretation("wills smith", 0.9, true, false), utils.createInterpretation("will smith", 1.0, false, true));
    utils.assertRewrittenQuery("?query=willl+smith&QRWChain=" + US_MARKET_SEARCH_CHAIN + "&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" + MISSPELL_REWRITER_NAME + "." + RewriterConstants.QSS_SUGG + "=true&" + NAME_REWRITER_NAME + "." + RewriterConstants.REWRITES_AS_UNIT_EQUIV + "=true&" + NAME_REWRITER_NAME + "." + RewriterConstants.ORIGINAL_AS_UNIT_EQUIV + "=true", "query 'OR (AND willl smith) (AND will smith) " + "\"will smith\" \"will smith movies\" " + "\"will smith news\" \"will smith imdb\" " + "\"will smith lyrics\" \"will smith dead\" " + "\"will smith nfl\" \"will smith new movie hancock\" " + "\"will smith biography\"'", intentModel);
}
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)

Example 4 with SearchChainRegistry

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

the class OutputSearchChain method invoke.

public void invoke(Request request) {
    try {
        SearchHandler searchHandler = SearcherUtils.getSearchHandler();
        SearchChainRegistry searchChainRegistry = searchHandler.getSearchChainRegistry();
        SearchChain searchChain = getSearchChain(searchChainRegistry, getSearchChainName(request));
        SearchChainTextRepresentation textRepresentation = new SearchChainTextRepresentation(searchChain, searchChainRegistry);
        request.returnValues().add(new StringValue(textRepresentation.toString()));
    } catch (Exception e) {
        request.setError(1000, Exceptions.toMessageString(e));
    }
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) SearchChain(com.yahoo.search.searchchain.SearchChain) StringValue(com.yahoo.jrt.StringValue)

Example 5 with SearchChainRegistry

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

the class SearcherUtils method allSearchers.

private static Collection<Searcher> allSearchers() {
    SearchChainRegistry searchChainRegistry = getSearchHandler().getSearchChainRegistry();
    ComponentRegistry<Searcher> searcherRegistry = searchChainRegistry.getSearcherRegistry();
    return searcherRegistry.allComponents();
}
Also used : ClusterSearcher(com.yahoo.prelude.cluster.ClusterSearcher) Searcher(com.yahoo.search.Searcher) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry)

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