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