public static SearchResponse createSearchResponse()

in tablestore/src/main/java/com/alicloud/openservices/tablestore/core/protocol/ResponseFactory.java [779:825]


    public static SearchResponse createSearchResponse(ResponseContentWithMeta response,
        Search.SearchResponse searchResponse) throws IOException {
        SearchResponse result = new SearchResponse(response.getMeta());
        result.setTotalCount(searchResponse.getTotalHits());
        result.setAllSuccess(searchResponse.getIsAllSucceeded());
        result.setBodyBytes(searchResponse.getSerializedSize());
        List<Row> rows = new ArrayList<Row>();
        List<SearchHit> searchHits = new ArrayList<SearchHit>();
        for (int i = 0; i < searchResponse.getRowsCount(); ++i) {
            com.aliyun.ots.thirdparty.com.google.protobuf.ByteString bytes = searchResponse.getRows(i);
            PlainBufferCodedInputStream coded = new PlainBufferCodedInputStream(
                new PlainBufferInputStream(bytes.asReadOnlyByteBuffer()));
            List<PlainBufferRow> plainBufferRows = coded.readRowsWithHeader();
            if (plainBufferRows.size() != 1) {
                throw new IOException("Expect only returns one row. Row count: " + rows.size());
            }
            Row row = PlainBufferConversion.toRow(plainBufferRows.get(0));
            rows.add(row);
        }

        if(searchResponse.getRowsCount() != searchResponse.getSearchHitsCount() && searchResponse.getSearchHitsCount() != 0) {
            LOGGER.error("the row count is not equal to search extra result item count in server response body, ignore the search extra result items.");
        } else {
            for (int i = 0; i < searchResponse.getSearchHitsCount(); i++) {
                searchHits.add(toSearchHit(searchResponse.getSearchHits(i), rows.get(i)));
            }
        }
        result.setRows(rows);
        result.setSearchHits(searchHits);

        if (searchResponse.hasNextToken()) {
            result.setNextToken(searchResponse.getNextToken().toByteArray());
        }
        if (searchResponse.hasAggs()) {
            result.setAggregationResults(buildAggregationResultsFromByteString(searchResponse.getAggs()));
        }
        if (searchResponse.hasGroupBys()) {
            result.setGroupByResults(buildGroupByResultsFromByteString(searchResponse.getGroupBys()));
        }
        if (searchResponse.hasConsumed() && searchResponse.getConsumed().hasCapacityUnit()) {
            result.setConsumed(new ConsumedCapacity(OTSProtocolParser.parseCapacityUnit(searchResponse.getConsumed().getCapacityUnit())));
        }
        if (searchResponse.hasReservedConsumed() && searchResponse.getReservedConsumed().hasCapacityUnit()) {
            result.setReservedConsumed(new ConsumedCapacity(OTSProtocolParser.parseCapacityUnit(searchResponse.getReservedConsumed().getCapacityUnit())));
        }
        return result;
    }