All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.redisearch.AggregationResult Maven / Gradle / Ivy

The newest version!
package io.redisearch;

import io.redisearch.aggregation.Row;
import redis.clients.jedis.exceptions.JedisDataException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mnunberg on 2/22/18.
 */
public class AggregationResult {

    public final long totalResults;

    private long cursorId = -1;
    private final List> results = new ArrayList<>();
    
    public AggregationResult(List resp, long cursorId) {
      this(resp);
      this.cursorId = cursorId;
    }
    public AggregationResult(List resp) {
        // the first element is always the number of results
        totalResults = (Long) resp.get(0);    	

        for (int i = 1; i < resp.size(); i++) {
            List raw = (List)resp.get(i);
            Map cur = new HashMap<>();
            for (int j = 0; j < raw.size(); j += 2) {
                Object r = raw.get(j);
                if(r instanceof JedisDataException) {
                  throw (JedisDataException)r;
                }
                cur.put(new String((byte[])r), raw.get(j+1));
            }
            results.add(cur);
        }
    }

    public List> getResults() {
        return results;
    }
    public Row getRow(int index) {
        if (index >= results.size()) {
            return null;
        }
        return new Row(results.get(index));
    }
    
    public long getCursorId() {
      return cursorId;
    }
}