Search in sources :

Example 46 with Execution

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

the class GetSearcherTestCase method testQueryOverridesDefaults.

@Test
public void testQueryOverridesDefaults() 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);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4&priority=LOW_2&route=highwaytohell&timeout=58"));
    assertEquals(2, factory.messages.size());
    long lastTimeout = 58000;
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(DocumentProtocol.Priority.LOW_2, gdm.getPriority());
        assertEquals(Route.parse("highwaytohell"), gdm.getRoute());
        assertTrue(lastTimeout >= gdm.getTimeRemaining());
        lastTimeout = gdm.getTimeRemaining();
    }
    {
        Message m = factory.messages.get(1);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:3:4", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(DocumentProtocol.Priority.LOW_2, gdm.getPriority());
        assertEquals(Route.parse("highwaytohell"), gdm.getRoute());
        assertTrue(lastTimeout >= 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) 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 47 with Execution

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

the class GetSearcherTestCase method testGetSingleDocumentQuery.

@Test
public void testGetSingleDocumentQuery() throws Exception {
    // Needs auto-reply
    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);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:1:2"));
    System.out.println("HTTP request is " + result.getQuery().getHttpRequest());
    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("userdoc:kittens:1:2", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
    }
    assertEquals(1, result.hits().size());
    assertHits(result.hits(), "userdoc:kittens:1:2");
    // By default, document hit should not have its hit fields set
    DocumentHit hit = (DocumentHit) result.hits().get(0);
    assertEquals(0, hit.fieldKeys().size());
}
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) 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 48 with Execution

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

the class GetSearcherTestCase method testDocumentFieldWithDocumentNotFound.

@Test
public void testDocumentFieldWithDocumentNotFound() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType, null, true);
    factory.setNullReply(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=userdoc:kittens:1:2&field=name"));
    assertNotNull(result.hits().getErrorHit());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"16\" message=\"Resource not found.: " + "Document not found, could not return field 'name'\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) Searcher(com.yahoo.search.Searcher) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 49 with Execution

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

the class GetSearcherTestCase method testDocumentHitWithPopulatedHitFields.

@Test
public void testDocumentHitWithPopulatedHitFields() 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) };
    // Use a predefined reply list to ensure messages are answered out of order
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:1234:foo&populatehitfields=true"));
    assertEquals(1, result.hits().size());
    assertHits(result.hits(), "userdoc:kittens:1234:foo");
    DocumentHit hit = (DocumentHit) result.hits().get(0);
    Iterator<Map.Entry<String, Object>> iter = hit.fieldIterator();
    Set<String> fieldSet = new TreeSet<>();
    while (iter.hasNext()) {
        Map.Entry<String, Object> kv = iter.next();
        StringBuilder field = new StringBuilder();
        field.append(kv.getKey()).append(" -> ").append(kv.getValue());
        fieldSet.add(field.toString());
    }
    StringBuilder fields = new StringBuilder();
    for (String s : fieldSet) {
        fields.append(s).append("\n");
    }
    assertEquals("description -> supercat\n" + "documentid -> userdoc:kittens:1234:foo\n" + "fluffiness -> 10000\n" + "name -> megacat\n", fields.toString());
}
Also used : 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) TreeSet(java.util.TreeSet) Map(java.util.Map) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 50 with Execution

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

the class GetSearcherTestCase method deserializationExceptionsAreHandledGracefully.

@Test
public void deserializationExceptionsAreHandledGracefully() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
    GetDocumentReply[] replies = new GetDocumentReply[] { new MockFailingGetDocumentReply(doc1) };
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:5:1"));
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"18\" message=\"Internal server error.: " + "Got exception of type java.lang.RuntimeException during document " + "deserialization: epic dragon attack\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Result(com.yahoo.search.Result) Test(org.junit.Test)

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