Search in sources :

Example 1 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply 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 2 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply 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)

Example 3 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class GetSearcherTestCase method testDefaultDocumentHitRendering.

@Test
public void testDefaultDocumentHitRendering() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:3:4"));
    doc1.setFieldValue("name", new StringFieldValue("mittens"));
    doc1.setFieldValue("description", new StringFieldValue("it's a cat"));
    doc1.setFieldValue("fluffiness", new IntegerFieldValue(8));
    Document doc2 = new Document(docType, new DocumentId("userdoc:kittens:1:2"));
    doc2.setFieldValue("name", new StringFieldValue("garfield"));
    doc2.setFieldValue("description", new StringFieldValue("preliminary research indicates <em>hatred</em> of mondays. caution advised"));
    doc2.setFieldValue("fluffiness", new IntegerFieldValue(2));
    Document doc3 = new Document(docType, new DocumentId("userdoc:kittens:77:88"));
    GetDocumentReply errorReply = new GetDocumentReply(doc3);
    errorReply.addError(new com.yahoo.messagebus.Error(123, "userdoc:kittens:77:88 had fleas."));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1), new GetDocumentReply(doc2), errorReply };
    // Use a predefined reply list to ensure messages are answered out of order
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result xmlResult = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:77:88&id[1]=userdoc:kittens:1:2&id[2]=userdoc:kittens:3:4"));
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"messagebus\" code=\"123\" message=\"userdoc:kittens:77:88 had fleas.\"/>\n" + "</errors>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:kittens:1:2\">\n" + "  <name>garfield</name>\n" + "  <description>preliminary research indicates &lt;em&gt;hatred&lt;/em&gt; of mondays. caution advised</description>\n" + "  <fluffiness>2</fluffiness>\n" + "</document>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:kittens:3:4\">\n" + "  <name>mittens</name>\n" + "  <description>it's a cat</description>\n" + "  <fluffiness>8</fluffiness>\n" + "</document>\n" + "</result>\n", xmlResult);
}
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) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 4 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class GetSearcherTestCase method testDocumentFieldNoContentType.

@Test
public void testDocumentFieldNoContentType() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
    doc1.setFieldValue("name", "derrick");
    doc1.setFieldValue("description", "kommisar katze");
    doc1.setFieldValue("fluffiness", 0);
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:5:1&field=description"));
    assertNull(result.hits().getErrorHit());
    assertEquals("text/xml", result.getTemplating().getTemplates().getMimeType());
    assertEquals("UTF-8", result.getTemplating().getTemplates().getEncoding());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>kommisar katze</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)

Example 5 with GetDocumentReply

use of com.yahoo.documentapi.messagebus.protocol.GetDocumentReply in project vespa by vespa-engine.

the class GetSearcherTestCase method testDocumentFieldRawContent.

@Test
public void testDocumentFieldRawContent() throws Exception {
    byte[] contentBytes = new byte[] { 0, -128, 127 };
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:123:456"));
    doc1.setFieldValue("foo", new Raw(ByteBuffer.wrap(contentBytes)));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:123:456&field=foo"));
    assertNull(result.hits().getErrorHit());
    assertEquals("application/octet-stream", result.getTemplating().getTemplates().getMimeType());
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    SearchRendererAdaptor.callRender(stream, result);
    stream.flush();
    byte[] resultBytes = stream.toByteArray();
    assertEquals(contentBytes.length, resultBytes.length);
    for (int i = 0; i < resultBytes.length; ++i) {
        assertEquals(contentBytes[i], resultBytes[i]);
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) Raw(com.yahoo.document.datatypes.Raw) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)19 Test (org.junit.Test)17 Result (com.yahoo.search.Result)13 Searcher (com.yahoo.search.Searcher)13 Execution (com.yahoo.search.searchchain.Execution)13 Document (com.yahoo.document.Document)4 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 Chain (com.yahoo.component.chain.Chain)2 DocumentId (com.yahoo.document.DocumentId)2 Raw (com.yahoo.document.datatypes.Raw)2 FeedContext (com.yahoo.feedapi.FeedContext)2 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)2 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)2 Reply (com.yahoo.messagebus.Reply)2 ClusterList (com.yahoo.vespaclient.ClusterList)2 DocumentAccessException (com.yahoo.documentapi.DocumentAccessException)1 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)1 RemoveDocumentReply (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply)1 UpdateDocumentReply (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentReply)1