Search in sources :

Example 46 with DocumentType

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

the class DocumentModelBuilder method extractNestedTypes.

private static void extractNestedTypes(NewDocumentType dt, DataType type) {
    if (type instanceof StructDataType) {
        StructDataType tmp = (StructDataType) type;
        extractDataTypesFromFields(dt, tmp.getFieldsThisTypeOnly());
    } else if (type instanceof DocumentType) {
        throw new IllegalArgumentException("Can not handle nested document definitions. In document type '" + dt.getName().toString() + "', we can not define document type '" + type.toString());
    } else if (type instanceof CollectionDataType) {
        CollectionDataType tmp = (CollectionDataType) type;
        extractNestedTypes(dt, tmp.getNestedType());
        addType(dt, tmp.getNestedType());
    } else if (type instanceof MapDataType) {
        MapDataType tmp = (MapDataType) type;
        extractNestedTypes(dt, tmp.getKeyType());
        extractNestedTypes(dt, tmp.getValueType());
        addType(dt, tmp.getKeyType());
        addType(dt, tmp.getValueType());
    } else if (type instanceof TemporaryAnnotationReferenceDataType) {
        throw new IllegalArgumentException(type.toString());
    }
}
Also used : StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) DocumentType(com.yahoo.document.DocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) VespaDocumentType(com.yahoo.documentmodel.VespaDocumentType) MapDataType(com.yahoo.document.MapDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)

Example 47 with DocumentType

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

the class JDiscContainerDocprocTest method requireThatBasicDocumentProcessingWorks.

@Test
public void requireThatBasicDocumentProcessingWorks() throws Exception {
    try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).documentType("music", DOCUMENT).build()) {
        JDisc container = app.getJDisc("container");
        DocumentProcessing docProc = container.documentProcessing();
        DocumentType type = docProc.getDocumentTypes().get("music");
        ChainRegistry<DocumentProcessor> chains = docProc.getChains();
        assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
        Document doc = new Document(type, "doc:this:is:a:great:album");
        doc.setFieldValue("title", "Great Album!");
        com.yahoo.docproc.Processing processing;
        DocumentProcessor.Progress progress;
        DocumentPut put = new DocumentPut(doc);
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
    }
}
Also used : Rot13DocumentProcessor(com.yahoo.application.container.docprocs.Rot13DocumentProcessor) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) ApplicationBuilder(com.yahoo.application.ApplicationBuilder) Application(com.yahoo.application.Application) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 48 with DocumentType

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

the class EntryTestCase method testEquals.

public void testEquals() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg");
    DocumentType bmType = manager.getDocumentType("benchmark");
    DocumentPut put1 = new DocumentPut(bmType, "userdoc:foo:99999999:1");
    DocumentPut put2 = new DocumentPut(bmType, "userdoc:foo:99999999:2");
    Entry entry1 = Entry.create(put1);
    Entry entry2 = Entry.create(put1);
    assert (entry1.equals(entry2));
    Entry entry3 = Entry.create(put2);
    assert (!entry1.equals(entry3));
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType)

Example 49 with DocumentType

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

the class EntryTestCase method testHashCode.

public void testHashCode() {
    DocumentTypeManager manager = new DocumentTypeManager();
    DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg");
    DocumentType bmType = manager.getDocumentType("benchmark");
    DocumentPut put1 = new DocumentPut(bmType, "userdoc:foo:99999999:1");
    DocumentPut put2 = new DocumentPut(bmType, "userdoc:foo:99999999:2");
    Entry entry1 = Entry.create(put1);
    Entry entry2 = Entry.create(put1);
    assert (entry1.hashCode() == entry2.hashCode());
    Entry entry3 = Entry.create(put2);
    assert (entry1.hashCode() != entry3.hashCode());
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType)

Example 50 with DocumentType

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

the class VisitorSearcherTestCase method setUp.

@org.junit.Before
public void setUp() {
    docMan = new DocumentTypeManager();
    docType = new DocumentType("kittens");
    docType.addHeaderField("name", DataType.STRING);
    docType.addField("description", DataType.STRING);
    docType.addField("image", DataType.RAW);
    docType.addField("fluffiness", DataType.INT);
    docType.addField("foo", DataType.RAW);
    docMan.registerDocumentType(docType);
    factory = new DocumentSessionFactory(docType);
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType)

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