Search in sources :

Example 91 with DocumentType

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

the class StringTestCase method consume.

public Document consume(Document document, DocumentTypeManager docTypeMgr) {
    DocumentType type = docTypeMgr.getDocumentType("blog");
    Collection<Field> fc = type.getFields();
    for (Field f : fc) {
        System.out.println("\n\nField Name: " + f.getName());
        System.out.println("DataType: " + f.getDataType());
        System.out.println("isHeader? " + f.isHeader());
        FieldValue val = document.getFieldValue(f);
        if (val instanceof StringFieldValue) {
            StringFieldValue sfv = (StringFieldValue) val;
            System.out.println(f.getName() + " is a StringField. Field Value: " + sfv.getString());
            Collection<SpanTree> c = sfv.getSpanTrees();
            for (SpanTree tree : c) {
                System.out.println(f.getName() + " has annotations");
                consumeAnnotations(tree, (SpanList) tree.getRoot());
            }
        }
    }
    return document;
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) SpanTree(com.yahoo.document.annotation.SpanTree)

Example 92 with DocumentType

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

the class XmlDocumentWriterTestCase method requireThatPredicateFieldValuesAreSerializedAsString.

@Test
public void requireThatPredicateFieldValuesAreSerializedAsString() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_predicate", DataType.PREDICATE);
    docType.addField(field);
    Document doc = new Document(docType, "doc:scheme:");
    PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class);
    doc.setFieldValue("my_predicate", predicate);
    new XmlDocumentWriter().write(doc);
    Mockito.verify(predicate, Mockito.times(1)).printXml(Mockito.any(XmlStream.class));
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Example 93 with DocumentType

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

the class VespaDocumentDeserializer42 method readDocumentType.

public DocumentType readDocumentType() {
    Utf8Array docTypeName = parseNullTerminatedString();
    // used to hold the version
    int ignored = getShort(null);
    DocumentType docType = manager.getDocumentType(new DataTypeName(docTypeName));
    if (docType == null) {
        throw new DeserializationException("No known document type with name " + new Utf8String(docTypeName).toString());
    }
    return docType;
}
Also used : Utf8String(com.yahoo.text.Utf8String) DocumentType(com.yahoo.document.DocumentType) DataTypeName(com.yahoo.document.DataTypeName) Utf8Array(com.yahoo.text.Utf8Array)

Example 94 with DocumentType

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

the class Bug4261985TestCase method testAnnotate.

@Test
public void testAnnotate() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.bug4261985.cfg");
    DocumentType type = manager.getDocumentType("blog");
    Document doc = new Document(type, "doc:this:is:a:test");
    doc.setFieldValue("body", new StringFieldValue("bla bla bla bla bla bla bla" + "bla bla bla bla bla bla bla"));
    annotate(doc, manager);
    GrowableByteBuffer buf = new GrowableByteBuffer();
    doc.serialize(buf);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 95 with DocumentType

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

the class Bug4259784TestCase method testSerialize.

@Test
public void testSerialize() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/java/com/yahoo/document/annotation/documentmanager.bug4259784.cfg");
    DocumentType type = manager.getDocumentType("blog");
    Document doc = new Document(type, "doc:this:is:a:test");
    doc.setFieldValue("body", new StringFieldValue("bla bla bla bla bla bla bla" + "bla bla bla bla bla bla bla"));
    annotate(doc, manager);
    GrowableByteBuffer buf = new GrowableByteBuffer();
    doc.serialize(buf);
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

DocumentType (com.yahoo.document.DocumentType)98 Test (org.junit.Test)45 Document (com.yahoo.document.Document)41 DocumentPut (com.yahoo.document.DocumentPut)35 Field (com.yahoo.document.Field)24 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)24 DocumentId (com.yahoo.document.DocumentId)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)19 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)17 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)17 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)17 DocumentUpdate (com.yahoo.document.DocumentUpdate)15 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)15 StructDataType (com.yahoo.document.StructDataType)14 TensorDataType (com.yahoo.document.TensorDataType)12 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)11 ArrayDataType (com.yahoo.document.ArrayDataType)10 MapDataType (com.yahoo.document.MapDataType)10 ReferenceDataType (com.yahoo.document.ReferenceDataType)10