use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class ExecutionTestCase method testContextCache.
public void testContextCache() {
IndexFacts[] contextsBefore = new IndexFacts[5];
IndexFacts[] contextsAfter = new IndexFacts[5];
List<Searcher> l = new ArrayList<>(5);
l.add(new ContextCacheSearcher(0, contextsBefore, contextsAfter));
l.add(new ContextCacheSearcher(1, contextsBefore, contextsAfter));
l.add(new ContextCacheSearcher(2, contextsBefore, contextsAfter));
l.add(new ContextCacheSearcher(3, contextsBefore, contextsAfter));
l.add(new ContextCacheSearcher(4, contextsBefore, contextsAfter));
Chain<Searcher> chain = new Chain<>(l);
Query query = new Query("?mutatecontext=2");
new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSame(contextsBefore[0], contextsAfter[0]);
assertSame(contextsBefore[1], contextsAfter[1]);
assertSame(contextsBefore[2], contextsAfter[2]);
assertSame(contextsBefore[3], contextsAfter[3]);
assertSame(contextsBefore[4], contextsAfter[4]);
assertSame(contextsBefore[0], contextsBefore[1]);
assertNotSame(contextsBefore[1], contextsBefore[2]);
assertSame(contextsBefore[2], contextsBefore[3]);
assertSame(contextsBefore[3], contextsBefore[4]);
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class CJKSearcherTestCase method assertTransformed.
private void assertTransformed(String queryString, String expected, Query.Type mode, Language actualLanguage, Language queryLanguage, Linguistics linguistics) {
Parser parser = ParserFactory.newInstance(mode, new ParserEnvironment().setIndexFacts(indexFacts).setLinguistics(linguistics));
Item root = parser.parse(new Parsable().setQuery(queryString).setLanguage(actualLanguage)).getRoot();
assertFalse(root instanceof NullItem);
Query query = new Query("?language=" + queryLanguage.languageCode());
query.getModel().getQueryTree().setRoot(root);
new Execution(new Chain<Searcher>(new CJKSearcher()), new Execution.Context(null, indexFacts, null, null, linguistics)).search(query);
assertEquals(expected, query.getModel().getQueryTree().getRoot().toString());
}
use of com.yahoo.component.chain.Chain 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);
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class NGramSearcherTestCase method testNGramRecombining.
public void testNGramRecombining() {
Query q = new Query("?query=ignored");
Result r = new Execution(new Chain<>(searcher, new MockBackend1()), createContextStub(indexFacts)).search(q);
Hit h1 = r.hits().get("hit1");
assertEquals("Should be untouched,\u001feven if containing \u001f", h1.getField("test").toString());
assertTrue(h1.getField("test") instanceof String);
assertEquals("Blue red Ed A", h1.getField("gram2").toString());
assertTrue(h1.getField("gram2") instanceof XMLString);
assertEquals("Separators on borders work", "Blue red ed a\u001f", h1.getField("gram3").toString());
assertTrue(h1.getField("gram3") instanceof String);
Hit h2 = r.hits().get("hit2");
assertEquals("katt i...morgen", h2.getField("gram3").toString());
assertTrue(h2.getField("gram3") instanceof JSONString);
Hit h3 = r.hits().get("hit3");
assertEquals("\u001ffin\u001f \u001fen\u001f \u001fa\u001f", h3.getField("gram2").toString());
assertEquals("#Logging in #Java is like that \"Judean P\u001fopul\u001far Front\" scene from \"Life of Brian\".", h3.getField("gram3").toString());
}
use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.
the class FutureDataTestCase method testFederateSyncAndAsyncData.
/**
* Federate to one source which returns data immediately and one who return future data
*/
@SuppressWarnings("unchecked")
@Test
public void testFederateSyncAndAsyncData() throws InterruptedException, ExecutionException, TimeoutException {
// Set up
FutureDataSource futureDataSource = new FutureDataSource();
Chain<Processor> chain = new Chain<>(new DataCounter(), new Federator(new Chain<>(new DataSource()), new Chain<>(futureDataSource)));
// Execute
Request request = new Request();
request.properties().set("appendage", 1);
Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
// Verify the result prior to completion of delayed data
// The sync data list + the (currently empty) future data list) + the data count
assertEquals(3, response.data().asList().size());
DataList syncData = (DataList) response.data().get(0);
DataList asyncData = (DataList) response.data().get(1);
StringData countData = (StringData) response.data().get(2);
assertEquals("The sync data is available", 3, syncData.asList().size());
assertEquals("first.1", syncData.get(0).toString());
assertEquals("second.1", syncData.get(1).toString());
assertEquals("third.1", syncData.get(2).toString());
assertEquals("No async data yet", 0, asyncData.asList().size());
assertEquals("The data counter has run and accessed the sync data", "Data count: 3", countData.toString());
// complete async data
futureDataSource.incomingData.get(0).add(new StringData(request, "d1"));
futureDataSource.incomingData.get(0).addLast(new StringData(request, "d2"));
assertEquals("New data is not visible because we haven't asked for it", 0, asyncData.asList().size());
asyncData.complete().get(1000, TimeUnit.MILLISECONDS);
assertEquals("Now the data is available", 2, asyncData.asList().size());
assertEquals("d1", asyncData.get(0).toString().toString());
assertEquals("d2", asyncData.get(1).toString().toString());
}
Aggregations