Search in sources :

Example 76 with Searcher

use of com.yahoo.search.Searcher 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 77 with Searcher

use of com.yahoo.search.Searcher 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)

Example 78 with Searcher

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

the class GetSearcherTestCase method testQueryPassThroughAndGet.

/* Test that a query will contain both document hits and hits from a searcher
     * further down the chain, iff the searcher returns a DocumentHit.
     */
@Test
public void testQueryPassThroughAndGet() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:1234:foo"));
    doc1.setFieldValue("name", new StringFieldValue("megacat"));
    doc1.setFieldValue("description", new StringFieldValue("supercat"));
    doc1.setFieldValue("fluffiness", new IntegerFieldValue(10000));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, false, replies);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    DocumentHit backendHit = new DocumentHit(new Document(docType, new DocumentId("userdoc:kittens:5678:bar")), 5);
    Chain<Searcher> searchChain = new Chain<>(searcher, new MockBackend(backendHit));
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?query=flarn&id=userdoc:kittens:1234:foo"));
    assertEquals(1, factory.messages.size());
    assertEquals(2, result.hits().size());
    assertNotNull(result.hits().get("userdoc:kittens:5678:bar"));
    assertNotNull(result.hits().get("userdoc:kittens:1234:foo"));
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) 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 79 with Searcher

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

the class GetSearcherTestCase method testConfigChanges.

@Test
public void testConfigChanges() throws Exception {
    String config = "raw:timeout 37\nroute \"riksveg18\"\nretryenabled true";
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(new FeederConfig(new FeederConfig.Builder().timeout(58).route("riksveg18").retryenabled(true)), defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=doc:batman:dahnahnahnah"));
    assertEquals(1, factory.messages.size());
    assertEquals(1, factory.getSessionsCreated());
    {
        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("riksveg18"), gdm.getRoute());
        assertTrue(gdm.getRetryEnabled());
        assertTrue(58000 >= gdm.getTimeRemaining());
    }
    factory.messages.clear();
    FeederConfig newConfig = new FeederConfig(new FeederConfig.Builder().timeout(123).route("e6").retryenabled(false));
    searcher.getMessagePropertyProcessor().configure(newConfig, defLoadTypeCfg);
    new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=doc:spiderman:does_whatever_a_spider_can"));
    // riksveg18 is created again, and e6 is created as well.
    assertEquals(3, factory.getSessionsCreated());
    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:spiderman:does_whatever_a_spider_can", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(Route.parse("e6"), gdm.getRoute());
        assertFalse(gdm.getRetryEnabled());
        assertTrue(123000 >= 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) 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 80 with Searcher

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

the class GetSearcherTestCase method testResultWithSingleError.

@Test
public void testResultWithSingleError() throws Exception {
    com.yahoo.messagebus.Error err = new com.yahoo.messagebus.Error(32, "Alas, it went poorly");
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, err, true);
    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:1:2&id[1]=userdoc:kittens:3:4"));
    assertNotNull(result.hits().getErrorHit());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"messagebus\" code=\"32\" message=\"Alas, it went poorly\"/>\n" + "</errors>\n" + "</result>\n", result);
}
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) Test(org.junit.Test)

Aggregations

Searcher (com.yahoo.search.Searcher)130 Result (com.yahoo.search.Result)94 Execution (com.yahoo.search.searchchain.Execution)88 Query (com.yahoo.search.Query)82 Test (org.junit.Test)74 Chain (com.yahoo.component.chain.Chain)57 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 Hit (com.yahoo.search.result.Hit)17 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)14 HashMap (java.util.HashMap)14 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)11 FieldCollapsingSearcher (com.yahoo.prelude.searcher.FieldCollapsingSearcher)10 ArrayList (java.util.ArrayList)10 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)9 ComponentId (com.yahoo.component.ComponentId)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)8