Search in sources :

Example 61 with Field

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

the class JsonRendererTestCase method testFieldValueInHit.

@Test
public final void testFieldValueInHit() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"fromDocumentApi\":{\"integerField\":123, \"stringField\":\"abc\"}" + "                },\n" + "                \"id\": \"fieldValueTest\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("fieldValueTest");
    StructDataType structType = new StructDataType("jsonRenderer");
    structType.addField(new Field("stringField", DataType.STRING));
    structType.addField(new Field("integerField", DataType.INT));
    Struct struct = structType.createFieldValue();
    struct.setFieldValue("stringField", "abc");
    struct.setFieldValue("integerField", 123);
    h.setField("fromDocumentApi", struct);
    r.hits().add(h);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : Field(com.yahoo.document.Field) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) StructDataType(com.yahoo.document.StructDataType) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 62 with Field

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

the class DocumentScriptTestCase method requireThatLinguisticsSpanTreeIsRemovedFromStructStringFields.

@Test
public void requireThatLinguisticsSpanTreeIsRemovedFromStructStringFields() {
    StructDataType structType = new StructDataType("myStruct");
    structType.addField(new Field("myString", DataType.STRING));
    Struct in = new Struct(structType);
    in.setFieldValue("myString", newString(SpanTrees.LINGUISTICS, "mySpanTree"));
    Struct out = (Struct) processDocument(in);
    assertSpanTrees(out.getFieldValue("myString"), "mySpanTree");
    StringFieldValue str = (StringFieldValue) ((MapValueUpdate) processFieldUpdate(in)).getUpdate().getValue();
    assertSpanTrees(str, "mySpanTree");
    str = (StringFieldValue) ((MapValueUpdate) processFieldUpdate(in)).getUpdate().getValue();
    assertSpanTrees(str, "mySpanTree");
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 63 with Field

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

the class JsonReaderTestCase method setUp.

@Before
public void setUp() throws Exception {
    parserFactory = new JsonFactory();
    types = new DocumentTypeManager();
    {
        DocumentType x = new DocumentType("smoke");
        x.addField(new Field("something", DataType.STRING));
        x.addField(new Field("nalle", DataType.STRING));
        x.addField(new Field("int1", DataType.INT));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("mirrors");
        StructDataType woo = new StructDataType("woo");
        woo.addField(new Field("sandra", DataType.STRING));
        woo.addField(new Field("cloud", DataType.STRING));
        x.addField(new Field("skuggsjaa", woo));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testarray");
        DataType d = new ArrayDataType(DataType.STRING);
        x.addField(new Field("actualarray", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testset");
        DataType d = new WeightedSetDataType(DataType.STRING, true, true);
        x.addField(new Field("actualset", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testmap");
        DataType d = new MapDataType(DataType.STRING, DataType.STRING);
        x.addField(new Field("actualmap", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testraw");
        DataType d = DataType.RAW;
        x.addField(new Field("actualraw", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testMapStringToArrayOfInt");
        DataType value = new ArrayDataType(DataType.INT);
        DataType d = new MapDataType(DataType.STRING, value);
        x.addField(new Field("actualMapStringToArrayOfInt", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testsinglepos");
        DataType d = PositionDataType.INSTANCE;
        x.addField(new Field("singlepos", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testtensor");
        x.addField(new Field("mappedtensorfield", new TensorDataType(new TensorType.Builder().mapped("x").mapped("y").build())));
        x.addField(new Field("indexedtensorfield", new TensorDataType(new TensorType.Builder().indexed("x").indexed("y").build())));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testpredicate");
        x.addField(new Field("boolean", DataType.PREDICATE));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testint");
        x.addField(new Field("integerfield", DataType.INT));
        types.registerDocumentType(x);
    }
}
Also used : Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) StructDataType(com.yahoo.document.StructDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) JsonFactory(com.fasterxml.jackson.core.JsonFactory) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) MapDataType(com.yahoo.document.MapDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) PositionDataType(com.yahoo.document.PositionDataType) MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType) TensorType(com.yahoo.tensor.TensorType) Before(org.junit.Before)

Example 64 with Field

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

the class VespaDocumentSerializerTestCase method predicate_field_values_are_serialized.

@Test
public void predicate_field_values_are_serialized() {
    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);
    DocumentSerializerFactory.create42(new GrowableByteBuffer()).write(doc);
    Mockito.verify(predicate, Mockito.times(1)).serialize(Mockito.same(field), Mockito.any(FieldWriter.class));
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) Test(org.junit.Test)

Example 65 with Field

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

the class VespaXmlUpdateReaderTestCase method requireThatWSetItemDeserializeExceptionIncludesFieldName.

@Test
public void requireThatWSetItemDeserializeExceptionIncludesFieldName() throws Exception {
    Field field = new Field("my_field", DataType.getWeightedSet(DataType.BYTE));
    assertThrows(field, "<assign field='my_field'><item>-129</item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 83)");
    assertThrows(field, "<assign fieldpath='my_field'><item>-129</item></assign>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 87)");
    assertThrows(field, "<add field='my_field'><item>-129</item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 80)");
    assertThrows(field, "<add fieldpath='my_field'><item>-129</item></add>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 84)");
    assertThrows(field, "<remove field='my_field'><item>-129</item></remove>", "Field 'my_field': Invalid byte \"-129\". (at line 1, column 83)");
    try {
        readUpdate(field, "<remove fieldpath='my_field{-129}' />");
        fail();
    } catch (NumberFormatException e) {
    }
}
Also used : Field(com.yahoo.document.Field) Test(org.junit.Test)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5