Search in sources :

Example 1 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class VespaBackEndSearcher method addMetaInfo.

protected void addMetaInfo(Query query, QueryPacketData queryPacketData, QueryResultPacket resultPacket, Result result, boolean fromCache) {
    result.setTotalHitCount(resultPacket.getTotalDocumentCount());
    // Grouping
    if (resultPacket.getGroupData() != null) {
        byte[] data = resultPacket.getGroupData();
        ArrayList<Grouping> list = new ArrayList<>();
        BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer(ByteBuffer.wrap(data)));
        int cnt = buf.getInt(null);
        for (int i = 0; i < cnt; i++) {
            Grouping g = new Grouping();
            g.deserialize(buf);
            list.add(g);
        }
        GroupingListHit hit = new GroupingListHit(list, getDocsumDefinitionSet(query));
        hit.setQuery(result.getQuery());
        hit.setSource(getName());
        hit.setSourceNumber(sourceNumber);
        hit.setQueryPacketData(queryPacketData);
        result.hits().add(hit);
    }
    if (resultPacket.getCoverageFeature()) {
        result.setCoverage(new Coverage(resultPacket.getCoverageDocs(), resultPacket.getActiveDocs(), resultPacket.getNodesReplied()).setSoonActive(resultPacket.getSoonActiveDocs()).setDegradedReason(resultPacket.getDegradedReason()).setNodesTried(resultPacket.getNodesQueried()));
    }
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) ArrayList(java.util.ArrayList) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping) Coverage(com.yahoo.search.result.Coverage)

Example 2 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class ExpressionCountAggregationResultTest method testSerialization.

private void testSerialization(ExpressionCountAggregationResult from, ExpressionCountAggregationResult to) {
    BufferSerializer buffer = new BufferSerializer();
    from.serialize(buffer);
    buffer.flip();
    to.deserialize(buffer);
    assertEquals(from.getSketch(), to.getSketch());
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer)

Example 3 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class NormalSketchTest method testSerializationForPrecision.

private static void testSerializationForPrecision(int precision) {
    // precision p => 2^p bytes
    NormalSketch from = new NormalSketch(precision);
    for (int i = 0; i < from.size(); i++) {
        from.data()[i] = (byte) i;
    }
    NormalSketch to = new NormalSketch(precision);
    BufferSerializer buffer = new BufferSerializer();
    from.serialize(buffer);
    buffer.flip();
    to.deserialize(buffer);
    assertEquals(from, to);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer)

Example 4 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class StringTestCase method testSerializeDeserialize.

/*    public void testSpanTree() {
        StringFieldValue annotatedText = new StringFieldValue("banana airlines");
        SpanList lingTree = new SpanList();
        annotatedText.setSpanTree("linguistics", lingTree);
        for (Annotation anAnnotation : annotatedText.getSpanTree("linguistics")) {
            System.err.println(anAnnotation);
        }
    }*/
@Test
public void testSerializeDeserialize() throws Exception {
    java.lang.String test = "Hello hello";
    BufferSerializer data = new BufferSerializer(new GrowableByteBuffer(100, 2.0f));
    StringFieldValue value = new StringFieldValue(test);
    value.serialize(data);
    data.getBuf().position(0);
    StringFieldValue tmp = new StringFieldValue();
    DocumentDeserializer deser = DocumentDeserializerFactory.create42(null, data.getBuf());
    tmp.deserialize(deser);
    java.lang.String test2 = tmp.getString();
    assertEquals(test, test2);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Test(org.junit.Test) AbstractTypesTest(com.yahoo.document.annotation.AbstractTypesTest)

Example 5 with BufferSerializer

use of com.yahoo.vespa.objects.BufferSerializer in project vespa by vespa-engine.

the class DocumentIdTestCase method testSerializedDocumentIdCanContainNonTextCharacter.

@Test
public void testSerializedDocumentIdCanContainNonTextCharacter() throws UnsupportedEncodingException {
    // "id:a:b::0x7c"
    String strId = new String(new byte[] { 105, 100, 58, 97, 58, 98, 58, 58, 7, 99 });
    DocumentId docId = DocumentId.createFromSerialized(strId);
    {
        assertEquals(strId, docId.toString());
    }
    {
        BufferSerializer buf = new BufferSerializer();
        docId.serialize(buf);
        buf.flip();
        DocumentId deserializedId = new DocumentId(buf);
        assertEquals(strId, deserializedId.toString());
    }
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)21 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)9 Test (org.junit.Test)7 Grouping (com.yahoo.searchlib.aggregation.Grouping)4 Identifiable (com.yahoo.vespa.objects.Identifiable)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)1 Raw (com.yahoo.document.datatypes.Raw)1 LoadType (com.yahoo.documentapi.messagebus.loadtypes.LoadType)1 Coverage (com.yahoo.search.result.Coverage)1 Utf8Array (com.yahoo.text.Utf8Array)1 Utf8String (com.yahoo.text.Utf8String)1 DocumentSummary (com.yahoo.vdslib.DocumentSummary)1 SearchResult (com.yahoo.vdslib.SearchResult)1 FileOutputStream (java.io.FileOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1