Search in sources :

Example 11 with Raw

use of com.yahoo.document.datatypes.Raw in project vespa by vespa-engine.

the class DocumentTestCase method validateCppDocNotMap.

@SuppressWarnings("unchecked")
public void validateCppDocNotMap(Document doc) throws IOException {
    // in practice to validate v6 serialization
    assertEquals("doc:serializetest:http://test.doc.id/", doc.getId().toString());
    assertEquals(new IntegerFieldValue(5), doc.getFieldValue("intfield"));
    assertEquals(new FloatFieldValue((float) -9.23), doc.getFieldValue("floatfield"));
    assertEquals(new StringFieldValue("This is a string."), doc.getFieldValue("stringfield"));
    assertEquals(new LongFieldValue(398420092938472983L), doc.getFieldValue("longfield"));
    assertEquals(new DoubleFieldValue(98374532.398820d), doc.getFieldValue("doublefield"));
    assertEquals(new StringFieldValue("http://this.is.a.test/"), doc.getFieldValue("urifield"));
    // NOTE: The value really is unsigned 254, which becomes signed -2:
    assertEquals(new ByteFieldValue(-2), doc.getFieldValue("bytefield"));
    ByteBuffer raw = ByteBuffer.wrap("RAW DATA".getBytes());
    assertEquals(new Raw(raw), doc.getFieldValue("rawfield"));
    Document docindoc = (Document) doc.getFieldValue("docfield");
    assertEquals(docMan.getDocumentType("docindoc"), docindoc.getDataType());
    assertEquals(new DocumentId("doc:docindoc:http://embedded"), docindoc.getId());
    Array<FloatFieldValue> array = (Array<FloatFieldValue>) doc.getFieldValue("arrayoffloatfield");
    assertEquals(new FloatFieldValue(1.0f), array.get(0));
    assertEquals(new FloatFieldValue(2.0f), array.get(1));
    WeightedSet<StringFieldValue> wset = (WeightedSet<StringFieldValue>) doc.getFieldValue("wsfield");
    assertEquals(new Integer(50), wset.get(new StringFieldValue("Weighted 0")));
    assertEquals(new Integer(199), wset.get(new StringFieldValue("Weighted 1")));
}
Also used : DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Raw(com.yahoo.document.datatypes.Raw) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 12 with Raw

use of com.yahoo.document.datatypes.Raw in project vespa by vespa-engine.

the class DocumentTestCase method getSertestDocument.

private Document getSertestDocument() {
    Document doc = new Document(docMan.getDocumentType("sertest"), new DocumentId("doc:sertest:foobar"));
    doc.setFieldValue("mailid", "emailfromalicetobob");
    // 03/13/06 11:00:00
    doc.setFieldValue("date", -2013512400);
    doc.setFieldValue("attachmentcount", 2);
    byte[] rawBytes = new byte[100];
    for (int i = 0; i < rawBytes.length; i++) {
        rawBytes[i] = (byte) i;
    }
    doc.setFieldValue("rawfield", new Raw(ByteBuffer.wrap(rawBytes)));
    Document docInDoc = new Document(docMan.getDocumentType("docindoc"), new DocumentId("doc:sertest:inserted"));
    docInDoc.setFieldValue("tull", "ball");
    doc.setFieldValue("docindoc", docInDoc);
    WeightedSet<StringFieldValue> wset = new WeightedSet<>(DataType.getWeightedSet(DataType.STRING));
    wset.put(new StringFieldValue("this is a test"), 5);
    wset.put(new StringFieldValue("this is another test, blah blah"), 10);
    doc.setFieldValue("weightedfield", wset);
    MapFieldValue<StringFieldValue, StringFieldValue> map = new MapFieldValue<>(new MapDataType(DataType.STRING, DataType.STRING));
    map.put(new StringFieldValue("foo1"), new StringFieldValue("bar1"));
    map.put(new StringFieldValue("foo2"), new StringFieldValue("bar2"));
    doc.setFieldValue("mapfield", map);
    return doc;
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Raw(com.yahoo.document.datatypes.Raw) WeightedSet(com.yahoo.document.datatypes.WeightedSet)

Example 13 with Raw

use of com.yahoo.document.datatypes.Raw in project vespa by vespa-engine.

the class DocumentTestCaseBase method getTestDocument.

public Document getTestDocument() {
    Document doc = new Document(docMan.getDocumentType("testdoc"), new DocumentId("doc:testdoc:http://www.ntnu.no/"));
    doc.setFieldValue(byteField.getName(), (byte) 30);
    doc.setFieldValue(byteField.getName(), (byte) 30);
    doc.setFieldValue(intField.getName(), 50);
    ByteBuffer buf = ByteBuffer.allocate(7).put("hei der".getBytes());
    buf.flip();
    doc.setFieldValue(rawField, new Raw(buf));
    doc.setFieldValue(floatField, new FloatFieldValue((float) 3.56));
    doc.setFieldValue("stringattr", "tjohei");
    assertNotNull(doc.getId());
    assertNotNull(doc.getDataType());
    return doc;
}
Also used : Raw(com.yahoo.document.datatypes.Raw) ByteBuffer(java.nio.ByteBuffer) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue)

Aggregations

Raw (com.yahoo.document.datatypes.Raw)13 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Test (org.junit.Test)8 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)7 ByteBuffer (java.nio.ByteBuffer)6 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 WeightedSet (com.yahoo.document.datatypes.WeightedSet)5 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)4 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)4 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)4 FileOutputStream (java.io.FileOutputStream)4 Array (com.yahoo.document.datatypes.Array)3 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)3 Document (com.yahoo.document.Document)2 FieldValue (com.yahoo.document.datatypes.FieldValue)2 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)2 Result (com.yahoo.search.Result)2 Searcher (com.yahoo.search.Searcher)2 Execution (com.yahoo.search.searchchain.Execution)2