Search in sources :

Example 51 with Chain

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

the class SearchHandler method handleBody.

private HttpSearchResponse handleBody(HttpRequest request) {
    // Find query profile
    String queryProfileName = request.getProperty("queryProfile");
    CompiledQueryProfile queryProfile = queryProfileRegistry.findQueryProfile(queryProfileName);
    boolean benchmarkOutput = VespaHeaders.benchmarkOutput(request);
    // Create query
    Query query = new Query(request, queryProfile);
    boolean benchmarkCoverage = VespaHeaders.benchmarkCoverage(benchmarkOutput, request.getJDiscRequest().headers());
    // Find and execute search chain if we have a valid query
    String invalidReason = query.validate();
    Chain<Searcher> searchChain = null;
    String searchChainName = null;
    if (invalidReason == null) {
        Tuple2<String, Chain<Searcher>> nameAndChain = resolveChain(query.properties().getString(Query.SEARCH_CHAIN));
        searchChainName = nameAndChain.first;
        searchChain = nameAndChain.second;
    }
    // Create the result
    Result result;
    if (invalidReason != null) {
        result = new Result(query, ErrorMessage.createIllegalQuery(invalidReason));
    } else if (queryProfile == null && queryProfileName != null) {
        result = new Result(query, ErrorMessage.createIllegalQuery("Could not resolve query profile '" + queryProfileName + "'"));
    } else if (searchChain == null) {
        result = new Result(query, ErrorMessage.createInvalidQueryParameter("No search chain named '" + searchChainName + "' was found"));
    } else {
        String pathAndQuery = UriTools.rawRequest(request.getUri());
        result = search(pathAndQuery, query, searchChain, searchChainRegistry);
    }
    Renderer renderer;
    if (result.getTemplating().usesDefaultTemplate()) {
        renderer = toRendererCopy(query.getPresentation().getRenderer());
        // pre-Vespa 6 Result.getEncoding() expects this to be set. TODO: Remove
        result.getTemplating().setRenderer(renderer);
    } else {
        // somebody explicitly assigned a old style template
        renderer = perRenderingCopy(result.getTemplating().getRenderer());
    }
    // Transform result to response
    HttpSearchResponse response = new HttpSearchResponse(getHttpResponseStatus(request, result), result, query, renderer);
    if (hostResponseHeaderKey.isPresent())
        response.headers().add(hostResponseHeaderKey.get(), selfHostname);
    if (benchmarkOutput)
        VespaHeaders.benchmarkOutput(response.headers(), benchmarkCoverage, response.getTiming(), response.getHitCounts(), getErrors(result), response.getCoverage());
    return response;
}
Also used : Chain(com.yahoo.component.chain.Chain) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Renderer(com.yahoo.processing.rendering.Renderer) Result(com.yahoo.search.Result)

Example 52 with Chain

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

the class ApplicationStatusHandlerTest method chains_are_rendered.

@Test
public void chains_are_rendered() throws Exception {
    ChainRegistry<Processor> chains = new ChainRegistry<>();
    Chain<Processor> chain = new Chain<Processor>("myChain", new VoidProcessor(new ComponentId("voidProcessor")));
    chains.register(new ComponentId("myChain"), chain);
    String json = ApplicationStatusHandler.StatusResponse.renderChains(chains).toString();
    assertThat(json, containsString("myChain"));
    assertThat(json, containsString("voidProcessor"));
}
Also used : Chain(com.yahoo.component.chain.Chain) Processor(com.yahoo.processing.Processor) ChainRegistry(com.yahoo.processing.execution.chain.ChainRegistry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 53 with Chain

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

the class GetSearcherTestCase method testConfig.

@Test
public void testConfig() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(new FeederConfig(new FeederConfig.Builder().timeout(58).route("route66").retryenabled(false)), defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=doc:batman:dahnahnahnah"));
    assertEquals(1, factory.messages.size());
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("doc:batman:dahnahnahnah", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(Route.parse("route66"), gdm.getRoute());
        assertFalse(gdm.getRetryEnabled());
        assertTrue(58000 >= gdm.getTimeRemaining());
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) FeederConfig(com.yahoo.vespaclient.config.FeederConfig) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Example 54 with Chain

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

the class GetSearcherTestCase method testConsistentResultOrdering.

@Test
public void testConsistentResultOrdering() throws Exception {
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(new Document(docType, new DocumentId("userdoc:kittens:1:2"))), new GetDocumentReply(new Document(docType, new DocumentId("userdoc:kittens:7:8"))), new GetDocumentReply(new Document(docType, new DocumentId("userdoc:kittens:555:123"))) };
    // Use a predefined reply list to ensure messages are answered out of order
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, false, replies);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:555:123&id[1]=userdoc:kittens:1:2&id[2]=userdoc:kittens:7:8"));
    assertEquals(3, factory.messages.size());
    assertEquals(3, result.hits().size());
    // Hits must be in the same order as their document IDs in the query
    assertHits(result.hits(), "userdoc:kittens:555:123", "userdoc:kittens:1:2", "userdoc:kittens:7:8");
    assertEquals(0, ((DocumentHit) result.hits().get(0)).getIndex());
    assertEquals(1, ((DocumentHit) result.hits().get(1)).getIndex());
    assertEquals(2, ((DocumentHit) result.hits().get(2)).getIndex());
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 55 with Chain

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

the class GetSearcherTestCase method testGetMultipleDocumentsQueryAndPOST.

// Test that you can use both query string and POSTed IDs
@Test
public void testGetMultipleDocumentsQueryAndPOST() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    String data = "userdoc:kittens:5:6\nuserdoc:kittens:7:8\nuserdoc:kittens:9:10";
    MockHttpRequest request = new MockHttpRequest(data.getBytes("utf-8"), "/get/?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4");
    Query query = new Query(request.toRequest());
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(query);
    assertEquals(5, factory.messages.size());
    assertEquals(5, result.hits().size());
    assertNull(result.hits().getErrorHit());
    assertHits(result.hits(), "userdoc:kittens:1:2", "userdoc:kittens:3:4", "userdoc:kittens:5:6", "userdoc:kittens:7:8", "userdoc:kittens:9:10");
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) 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