Search in sources :

Example 86 with Chain

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]);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ArrayList(java.util.ArrayList)

Example 87 with Chain

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());
}
Also used : NullItem(com.yahoo.prelude.query.NullItem) Item(com.yahoo.prelude.query.Item) Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Parsable(com.yahoo.search.query.parser.Parsable) ParserEnvironment(com.yahoo.search.query.parser.ParserEnvironment) CJKSearcher(com.yahoo.prelude.querytransform.CJKSearcher) NullItem(com.yahoo.prelude.query.NullItem) Parser(com.yahoo.search.query.parser.Parser)

Example 88 with Chain

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);
}
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 89 with Chain

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());
}
Also used : Chain(com.yahoo.component.chain.Chain) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result)

Example 90 with Chain

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());
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) DataList(com.yahoo.processing.response.DataList) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Aggregations

Chain (com.yahoo.component.chain.Chain)92 Execution (com.yahoo.search.searchchain.Execution)59 Searcher (com.yahoo.search.Searcher)57 Test (org.junit.Test)56 Result (com.yahoo.search.Result)48 Query (com.yahoo.search.Query)47 FeedContext (com.yahoo.feedapi.FeedContext)21 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)21 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)21 ClusterList (com.yahoo.vespaclient.ClusterList)21 Processor (com.yahoo.processing.Processor)17 Request (com.yahoo.processing.Request)10 Response (com.yahoo.processing.Response)10 ComponentId (com.yahoo.component.ComponentId)8 FederationSearcher (com.yahoo.search.federation.FederationSearcher)8 ArrayList (java.util.ArrayList)8 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 Message (com.yahoo.messagebus.Message)7 Hit (com.yahoo.search.result.Hit)7 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)6