Search in sources :

Example 6 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class MockUserDatabaseClientTest method testClientExampleProcessor.

@Test
public void testClientExampleProcessor() {
    Request request = null;
    try {
        Chain<Processor> chain = new Chain<>("default", new MockUserDatabaseClient());
        setupJDisc(Collections.singletonList(chain));
        request = createRequest();
        Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);
        MockUserDatabaseClient.User user = (MockUserDatabaseClient.User) response.data().request().properties().get("User");
        assertNotNull(user);
        assertEquals("foo", user.getId());
    } finally {
        release(request);
    }
}
Also used : Response(com.yahoo.processing.Response) Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) Request(com.yahoo.processing.Request) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Test(org.junit.Test)

Example 7 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class FederationSearcher method fill.

@Override
public void fill(Result result, String summaryClass, Execution execution) {
    UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
    addResultsToFill(result.hits(), result, summaryClass, uniqueExecutionsToResults);
    Set<Entry<Chain<Searcher>, Map<Query, Result>>> resultsForAllChains = uniqueExecutionsToResults.resultsToFill.entrySet();
    int numberOfCallsToFillNeeded = 0;
    for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
        numberOfCallsToFillNeeded += resultsToFillForAChain.getValue().size();
    }
    List<Pair<Result, FutureResult>> futureFilledResults = new ArrayList<>();
    for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
        Chain<Searcher> chain = resultsToFillForAChain.getKey();
        Execution chainExecution = (chain == null) ? execution : new Execution(chain, execution.context());
        for (Entry<Query, Result> resultsToFillForAChainAndQuery : resultsToFillForAChain.getValue().entrySet()) {
            Result resultToFill = resultsToFillForAChainAndQuery.getValue();
            if (numberOfCallsToFillNeeded == 1) {
                chainExecution.fill(resultToFill, summaryClass);
                propagateErrors(resultToFill, result);
            } else {
                AsyncExecution asyncFill = new AsyncExecution(chainExecution);
                futureFilledResults.add(new Pair<>(resultToFill, asyncFill.fill(resultToFill, summaryClass)));
            }
        }
    }
    for (Pair<Result, FutureResult> futureFilledResult : futureFilledResults) {
        // futureFilledResult is a pair of a result to be filled and the future in which that same result is filled
        Optional<Result> filledResult = futureFilledResult.getSecond().getIfAvailable(result.getQuery().getTimeLeft(), TimeUnit.MILLISECONDS);
        if (filledResult.isPresent()) {
            // fill completed
            propagateErrors(filledResult.get(), result);
        } else {
            // fill timed out: Remove these hits as they are incomplete and may cause a race when accessed later
            result.hits().addError(futureFilledResult.getSecond().createTimeoutError());
            for (Iterator<Hit> i = futureFilledResult.getFirst().hits().unorderedDeepIterator(); i.hasNext(); ) {
                // Note that some of these hits may be filled, but as the fill thread may still be working on them
                // and we do not synchronize with it we need to discard all
                Hit removed = result.hits().remove(i.next().getId());
            }
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) FutureResult(com.yahoo.search.searchchain.FutureResult) Entry(java.util.Map.Entry) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) FutureResult(com.yahoo.search.searchchain.FutureResult) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) CopyOnWriteHashMap(com.yahoo.concurrent.CopyOnWriteHashMap) Pair(com.yahoo.collections.Pair)

Example 8 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class FederationSearcher method getSearchChainGroup.

private Result getSearchChainGroup(Hit hit, Result result, UniqueExecutionsToResults uniqueExecutionsToResults) {
    @SuppressWarnings("unchecked") Chain<Searcher> chain = (Chain<Searcher>) hit.getSearcherSpecificMetaData(this);
    Query query = hit.getQuery() != null ? hit.getQuery() : result.getQuery();
    return uniqueExecutionsToResults.get(chain, query);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher)

Example 9 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class FastSearcherTestCase method testPing.

@Test
public void testPing() throws IOException, InterruptedException {
    Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
    BackendTestCase.MockServer server = new BackendTestCase.MockServer();
    FS4ResourcePool listeners = new FS4ResourcePool(new Fs4Config(new Fs4Config.Builder()));
    Backend backend = listeners.getBackend(server.host.getHostString(), server.host.getPort());
    FastSearcher fastSearcher = new FastSearcher(backend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(0, 0.0d), documentdbInfoConfig);
    server.dispatch.packetData = BackendTestCase.PONG;
    server.dispatch.setNoChannel();
    Chain<Searcher> chain = new Chain<>(fastSearcher);
    Execution e = new Execution(chain, Execution.Context.createContextStub());
    Pong pong = e.ping(new Ping());
    assertTrue(pong.getPongPacket().isPresent());
    assertEquals(127, pong.getPongPacket().get().getDocstamp());
    backend.shutdown();
    server.dispatch.socket.close();
    server.dispatch.connection.close();
    server.worker.join();
    pong.setPingInfo("blbl");
    assertEquals("Result of pinging using blbl", pong.toString());
}
Also used : Chain(com.yahoo.component.chain.Chain) Searcher(com.yahoo.search.Searcher) Fs4Config(com.yahoo.container.search.Fs4Config) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) Execution(com.yahoo.search.searchchain.Execution) Ping(com.yahoo.prelude.Ping) Pong(com.yahoo.prelude.Pong) Test(org.junit.Test)

Example 10 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class PageTemplateSearcherTestCase method testSearcher.

public void testSearcher() {
    PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver());
    Chain<Searcher> chain = new Chain<>(s, new MockFederator());
    {
        // No template specified, should use default
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.resolver=native.deterministic"));
        assertSources("source1 source2", result);
    }
    {
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=oneSource&page.resolver=native.deterministic"));
        assertSources("source1", result);
    }
    {
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=twoSources&model.sources=source1&page.resolver=native.deterministic"));
        assertSources("source1", result);
    }
    {
        Query query = new Query("?query=foo&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", result);
    }
    {
        Query query = new Query("?query=foo&page.id=twoSourcesAndAny&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", result);
    }
    {
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source3", result);
    }
    {
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertTrue(query.getModel().getSources().isEmpty());
        assertNotNull(result.hits().get("source1"));
        assertNotNull(result.hits().get("source2"));
        assertNotNull(result.hits().get("source3"));
    }
    {
        Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", "source2", result);
    }
    {
        Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=test.firstChoice");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", "source1", result);
    }
    {
        // Specifying two templates, should pick the last
        Query query = new Query("?query=foo&page.id=threeSources+oneSource&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", "source1", result);
    }
    {
        // Specifying two templates as a list, should override the page.id setting
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        query.properties().set("page.idList", Arrays.asList("oneSource", "threeSources"));
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", "source1 source2 source3", result);
    }
    {
        try {
            Query query = new Query("?query=foo&page.id=oneSource+choiceOfSources&page.resolver=noneSuch");
            new Execution(chain, Execution.Context.createContextStub()).search(query);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            assertEquals("No page template resolver 'noneSuch'", e.getMessage());
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Result(com.yahoo.search.Result)

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