Search in sources :

Example 71 with Execution

use of com.yahoo.search.searchchain.Execution 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 72 with Execution

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

the class VespaAsyncSearcherTest method testAsyncExecution.

public void testAsyncExecution() {
    Chain<Searcher> chain = new Chain<>(new FirstSearcher(), new SecondSearcher());
    Execution execution = new Execution(chain, Execution.Context.createContextStub(null));
    Query query = new Query();
    // fails with exception on old versions
    execution.search(query);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher)

Example 73 with Execution

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

the class ConnectionControlSearcherTestCase method doSearch.

private Result doSearch(URI uri, long connectedAtMillis, long nowMillis) {
    SocketAddress remoteAddress = Mockito.mock(SocketAddress.class);
    Version version = Version.HTTP_1_1;
    Method method = Method.GET;
    CurrentContainer container = Mockito.mock(CurrentContainer.class);
    Mockito.when(container.newReference(Mockito.any())).thenReturn(Mockito.mock(Container.class));
    final com.yahoo.jdisc.http.HttpRequest serverRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(container, uri, method, version, remoteAddress, connectedAtMillis);
    HttpRequest incoming = new HttpRequest(serverRequest, new ByteArrayInputStream(new byte[0]));
    Query query = new Query(incoming);
    Execution e = new Execution(new Chain<Searcher>(ConnectionControlSearcher.createTestInstance(() -> nowMillis)), Execution.Context.createContextStub());
    Result r = e.search(query);
    return r;
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ConnectionControlSearcher(com.yahoo.search.searchers.ConnectionControlSearcher) Method(com.yahoo.jdisc.http.HttpRequest.Method) CurrentContainer(com.yahoo.jdisc.service.CurrentContainer) Result(com.yahoo.search.Result) Container(com.yahoo.jdisc.Container) CurrentContainer(com.yahoo.jdisc.service.CurrentContainer) Execution(com.yahoo.search.searchchain.Execution) Version(com.yahoo.jdisc.http.HttpRequest.Version) ByteArrayInputStream(java.io.ByteArrayInputStream) SocketAddress(java.net.SocketAddress)

Example 74 with Execution

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

the class LowercasingTestCase method testDisableLowercasingWeightedSet.

@Test
public void testDisableLowercasingWeightedSet() {
    execution = new Execution(new Chain<Searcher>(new VespaLowercasingSearcher(new LowercasingConfig(new LowercasingConfig.Builder().transform_weighted_sets(false)))), Execution.Context.createContextStub(settings));
    Query q = new Query();
    AndItem root = new AndItem();
    WeightedSetItem tmp;
    tmp = new WeightedSetItem(BAMSE);
    tmp.addToken("AbC", 3);
    root.addItem(tmp);
    tmp = new WeightedSetItem(TEDDY);
    tmp.addToken("dEf", 5);
    root.addItem(tmp);
    q.getModel().getQueryTree().setRoot(root);
    Result r = execution.search(q);
    root = (AndItem) r.getQuery().getModel().getQueryTree().getRoot();
    WeightedSetItem w0 = (WeightedSetItem) root.getItem(0);
    WeightedSetItem w1 = (WeightedSetItem) root.getItem(1);
    assertEquals(1, w0.getNumTokens());
    assertEquals(1, w1.getNumTokens());
    assertEquals("AbC", w0.getTokens().next().getKey());
    assertEquals("dEf", w1.getTokens().next().getKey());
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) AndItem(com.yahoo.prelude.query.AndItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 75 with Execution

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

the class QueryCombinatorTestCase method testDefaultIndexWithoutQuery.

public void testDefaultIndexWithoutQuery() {
    Query q = new Query("?defidx.juhu=b");
    Execution e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    e.search(q);
    assertEquals("NULL", q.getModel().getQueryTree().toString());
    q = new Query("?query=a&defidx.juhu=b");
    e = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts()));
    e.search(q);
    assertEquals("a", q.getModel().getQueryTree().toString());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts)

Aggregations

Execution (com.yahoo.search.searchchain.Execution)232 Query (com.yahoo.search.Query)184 Result (com.yahoo.search.Result)127 Test (org.junit.Test)123 Searcher (com.yahoo.search.Searcher)88 Chain (com.yahoo.component.chain.Chain)59 IndexFacts (com.yahoo.prelude.IndexFacts)34 Hit (com.yahoo.search.result.Hit)25 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 AndItem (com.yahoo.prelude.query.AndItem)18 WordItem (com.yahoo.prelude.query.WordItem)17 ComponentId (com.yahoo.component.ComponentId)13 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FastHit (com.yahoo.prelude.fastsearch.FastHit)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)13 ArrayList (java.util.ArrayList)12 CompositeItem (com.yahoo.prelude.query.CompositeItem)11