<commit_before>package org.lumongo.client.command;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.lumongo.client.pool.LumongoConnection;
import org.lumongo.client.result.QueryResult;
import org.lumongo.cluster.message.Lumongo.CountRequest;
import org.lumongo.cluster.message.Lumongo.ExternalService;
import org.lumongo.cluster.message.Lumongo.FacetRequest;
import org.lumongo.cluster.message.Lumongo.FieldSort;
import org.lumongo.cluster.message.Lumongo.FieldSort.Direction;
import org.lumongo.cluster.message.Lumongo.QueryRequest;
import org.lumongo.cluster.message.Lumongo.QueryResponse;
import org.lumongo.cluster.message.Lumongo.SortRequest;

import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;

/**
 * Runs a query on one of more LuMongo indexes.
 * @author mdavis
 *
 */
public class Query extends SimpleCommand<QueryRequest, QueryResult> {

    private String query;
    private int amount;
    private Collection<String> indexes;
    private Boolean realTime;
    private QueryResult lastResult;
    private List<CountRequest> countRequests;
    private List<String> drillDowns;
    private List<FieldSort> fieldSorts;

    public Query(String index, String query, int amount) {
        this(new String[] { index }, query, amount);
    }

    public Query(String[] indexes, String query, int amount) {
        this(new ArrayList<String>(Arrays.asList(indexes)), query, amount);
    }

    public Query(Collection<String> indexes, String query, int amount) {
        this.indexes = indexes;
        this.query = query;
        this.amount = amount;
        this.countRequests = new ArrayList<CountRequest>();
        this.drillDowns = new ArrayList<String>();
        this.fieldSorts = new ArrayList<FieldSort>();
    }

    public String getQuery() {
        return query;
    }

    public Query setQuery(String query) {
        this.query = query;
        return this;
    }

    public int getAmount() {
        return amount;
    }

    public Query setAmount(int amount) {
        this.amount = amount;
        return this;
    }

    public Query setIndexes(Collection<String> indexes) {
        this.indexes = indexes;
        return this;
    }

    public Collection<String> getIndexes() {
        return indexes;
    }

    public Query setRealTime(Boolean realTime) {
        this.realTime = realTime;
        return this;
    }

    public Boolean getRealTime() {
        return realTime;
    }

    public Query setLastResult(QueryResult lastResult) {
        this.lastResult = lastResult;
        return this;
    }

    public QueryResult getLastResult() {
        return lastResult;
    }

    public Query addDrillDown(String drillDown) {
        drillDowns.add(drillDown);
        return this;
    }

    public List<String> getDrillDowns() {
        return drillDowns;
    }

    public Query addCountRequest(String facet) {
        CountRequest countRequest = CountRequest.newBuilder().setFacet(facet).build();
        countRequests.add(countRequest);
        return this;
    }

    public Query addCountRequest(String facet, int maxFacets) {
        CountRequest countRequest = CountRequest.newBuilder().setFacet(facet).setMaxFacets(maxFacets).build();
        countRequests.add(countRequest);<commit_msg>Clean up facet api<commit_after>package org.lumongo.client.command;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.lumongo.LumongoConstants;
import org.lumongo.client.pool.LumongoConnection;
import org.lumongo.client.result.QueryResult;
import org.lumongo.cluster.message.Lumongo.CountRequest;
import org.lumongo.cluster.message.Lumongo.ExternalService;
import org.lumongo.cluster.message.Lumongo.FacetRequest;
import org.lumongo.cluster.message.Lumongo.FieldSort;
import org.lumongo.cluster.message.Lumongo.FieldSort.Direction;
import org.lumongo.cluster.message.Lumongo.QueryRequest;
import org.lumongo.cluster.message.Lumongo.QueryResponse;
import org.lumongo.cluster.message.Lumongo.SortRequest;
import org.lumongo.util.StringUtil;

import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;

/**
 * Runs a query on one of more LuMongo indexes.
 * @author mdavis
 *
 */
public class Query extends SimpleCommand<QueryRequest, QueryResult> {

    private String query;
    private int amount;
    private Collection<String> indexes;
    private Boolean realTime;
    private QueryResult lastResult;
    private List<CountRequest> countRequests;
    private List<String> drillDowns;
    private List<FieldSort> fieldSorts;

    public Query(String index, String query, int amount) {
        this(new String[] { index }, query, amount);
    }

    public Query(String[] indexes, String query, int amount) {
        this(new ArrayList<String>(Arrays.asList(indexes)), query, amount);
    }

    public Query(Collection<String> indexes, String query, int amount) {
        this.indexes = indexes;
        this.query = query;
        this.amount = amount;
        this.countRequests = new ArrayList<CountRequest>();
        this.drillDowns = new ArrayList<String>();
        this.fieldSorts = new ArrayList<FieldSort>();
    }

    public String getQuery() {
        return query;
    }

    public Query setQuery(String query) {
        this.query = query;
        return this;
    }

    public int getAmount() {
        return amount;
    }

    public Query setAmount(int amount) {
        this.amount = amount;
        return this;
    }

    public Query setIndexes(Collection<String> indexes) {
        this.indexes = indexes;
        return this;
    }

    public Collection<String> getIndexes() {
        return indexes;
    }

    public Query setRealTime(Boolean realTime) {
        this.realTime = realTime;
        return this;
    }

    public Boolean getRealTime() {
        return realTime;
    }

    public Query setLastResult(QueryResult lastResult) {
        this.lastResult = lastResult;
        return this;
    }

    public QueryResult getLastResult() {
        return lastResult;
    }

    public Query addDrillDown(String... drillDownParts) {
        drillDowns.add(StringUtil.join(LumongoConstants.FACET_DELIMITER, drillDownParts));
        return this;
    }

    public Query addDrillDown(String drillDown) {
        drillDowns.add(drillDown);
        return this;
    }

    public List<String> getDrillDowns() {
        return drillDowns;
    }

    public Query addCountRequest(String facet) {
        CountRequest countRequest = CountRequest.newBuilder().setFacet(facet).build();
        countRequests.add(countRequest);
        return this;
    }

    public Query addCountRequest(String facet, int maxFacets) {
        CountRequest countRequest = CountRequest.newBuilder().setFacet(facet).setMaxFacets(maxFacets).build();
        countRequests.add(countRequest);
{'fraction_non_alphanumeric': 0.09456537408101484, 'fraction_numerical': 0.0, 'mean_word_length': 3.1997578692493946, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7059608', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1982, 'n_words': 448}