Search in sources :

Example 41 with StringFieldValue

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

the class ToStringTestCase method requireThatValueIsConverted.

@Test
public void requireThatValueIsConverted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new IntegerFieldValue(69)).execute(new ToStringExpression());
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof StringFieldValue);
    assertEquals("69", ((StringFieldValue) val).getString());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 42 with StringFieldValue

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

the class ArithmeticTestCase method requireThatNonNumericOperandThrows.

@Test
public void requireThatNonNumericOperandThrows() {
    try {
        newArithmetic(new SetValueExpression(new IntegerFieldValue(6)), Operator.ADD, new SetValueExpression(new StringFieldValue("9"))).execute();
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Unsupported operation: [int] + [string]", e.getMessage());
    }
    try {
        newArithmetic(new SetValueExpression(new StringFieldValue("6")), Operator.ADD, new SetValueExpression(new IntegerFieldValue(9))).execute();
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Unsupported operation: [string] + [int]", e.getMessage());
    }
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 43 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue 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 44 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue 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 45 with StringFieldValue

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

the class SchemaMappingAndAccessesTest method getDoc.

private Document getDoc() {
    DocumentType type = new DocumentType("album");
    AnnotationType personType = new AnnotationType("person");
    Annotation person = new Annotation(personType);
    type.addField("title", DataType.STRING);
    type.addField("artist", DataType.STRING);
    type.addField("guitarist", DataType.STRING);
    type.addField("year", DataType.INT);
    type.addField("labels", DataType.getArray(DataType.STRING));
    Document doc = new Document(type, new DocumentId("doc:map:test:1"));
    doc.setFieldValue("title", new StringFieldValue("Black Rock"));
    StringFieldValue joe = new StringFieldValue("Joe Bonamassa");
    joe.setSpanTree(new SpanTree("mytree").annotate(person));
    doc.setFieldValue("artist", joe);
    doc.setFieldValue("year", new IntegerFieldValue(2010));
    Array<StringFieldValue> labels = new Array<>(type.getField("labels").getDataType());
    labels.add(new StringFieldValue("audun"));
    labels.add(new StringFieldValue("tylden"));
    doc.setFieldValue("labels", labels);
    StructDataType personStructType = new StructDataType("artist");
    personStructType.addField(new com.yahoo.document.Field("firstname", DataType.STRING));
    personStructType.addField(new com.yahoo.document.Field("lastname", DataType.STRING));
    type.addField("listeners", DataType.getArray(personStructType));
    Array<Struct> listeners = new Array<>(type.getField("listeners").getDataType());
    Struct listenerOne = new Struct(personStructType);
    listenerOne.setFieldValue("firstname", new StringFieldValue("per"));
    listenerOne.setFieldValue("lastname", new StringFieldValue("olsen"));
    Struct listenerTwo = new Struct(personStructType);
    listenerTwo.setFieldValue("firstname", new StringFieldValue("anders"));
    listenerTwo.setFieldValue("lastname", new StringFieldValue("and"));
    listeners.add(listenerOne);
    listeners.add(listenerTwo);
    doc.setFieldValue("listeners", listeners);
    return doc;
}
Also used : DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) AnnotationType(com.yahoo.document.annotation.AnnotationType) Annotation(com.yahoo.document.annotation.Annotation) Struct(com.yahoo.document.datatypes.Struct) Array(com.yahoo.document.datatypes.Array) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) SpanTree(com.yahoo.document.annotation.SpanTree)

Aggregations

StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)210 Test (org.junit.Test)136 FieldValue (com.yahoo.document.datatypes.FieldValue)49 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)40 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)37 Document (com.yahoo.document.Document)30 Array (com.yahoo.document.datatypes.Array)25 DocumentType (com.yahoo.document.DocumentType)21 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)21 Struct (com.yahoo.document.datatypes.Struct)21 DocumentPut (com.yahoo.document.DocumentPut)20 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)20 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)18 SpanTree (com.yahoo.document.annotation.SpanTree)15 FieldUpdate (com.yahoo.document.update.FieldUpdate)15 DocumentUpdate (com.yahoo.document.DocumentUpdate)12 Field (com.yahoo.document.Field)12 Annotation (com.yahoo.document.annotation.Annotation)12 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)12 HashMap (java.util.HashMap)12