Search in sources :

Example 36 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class SolrTable method getComp.

private StreamComparator getComp(List<? extends Map.Entry<String, String>> orders) {
    FieldComparator[] comps = new FieldComparator[orders.size()];
    for (int i = 0; i < orders.size(); i++) {
        Map.Entry<String, String> order = orders.get(i);
        String direction = getSortDirection(order);
        ComparatorOrder comparatorOrder = ComparatorOrder.fromString(direction);
        String sortKey = order.getKey();
        comps[i] = new FieldComparator(sortKey, comparatorOrder);
    }
    if (comps.length == 1) {
        return comps[0];
    } else {
        return new MultipleFieldComparator(comps);
    }
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder)

Example 37 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class SolrTable method bucketSortComp.

private static StreamComparator bucketSortComp(List<Bucket> buckets, Map<String, String> dirs) {
    FieldComparator[] comps = new FieldComparator[buckets.size()];
    for (int i = 0; i < buckets.size(); i++) {
        ComparatorOrder comparatorOrder = ComparatorOrder.fromString(dirs.get(buckets.get(i).toString()));
        String sortKey = buckets.get(i).toString();
        comps[i] = new FieldComparator(sortKey, comparatorOrder);
    }
    if (comps.length == 1) {
        return comps[0];
    } else {
        return new MultipleFieldComparator(comps);
    }
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder)

Example 38 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class SolrTable method bucketSortComp.

private static StreamComparator bucketSortComp(Bucket[] buckets, String dir) {
    FieldComparator[] comps = new FieldComparator[buckets.length];
    for (int i = 0; i < buckets.length; i++) {
        ComparatorOrder comparatorOrder = ascDescComp(dir);
        String sortKey = buckets[i].toString();
        comps[i] = new FieldComparator(sortKey, comparatorOrder);
    }
    if (comps.length == 1) {
        return comps[0];
    } else {
        return new MultipleFieldComparator(comps);
    }
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder)

Example 39 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class SolrTable method handleGroupByFacet.

private TupleStream handleGroupByFacet(String zkHost, String collection, final List<Map.Entry<String, Class>> fields, final String query, final List<Pair<String, String>> orders, final List<String> bucketFields, final List<Pair<String, String>> metricPairs, final String lim, final String havingPredicate) throws IOException {
    Map<String, Class> fmap = new HashMap();
    for (Map.Entry<String, Class> f : fields) {
        fmap.put(f.getKey(), f.getValue());
    }
    ModifiableSolrParams solrParams = new ModifiableSolrParams();
    solrParams.add(CommonParams.Q, query);
    Bucket[] buckets = buildBuckets(bucketFields, fields);
    Metric[] metrics = buildMetrics(metricPairs, true).toArray(new Metric[0]);
    if (metrics.length == 0) {
        metrics = new Metric[1];
        metrics[0] = new CountMetric();
    } else {
        for (Metric metric : metrics) {
            Class c = fmap.get(metric.getIdentifier());
            if (Long.class.equals(c)) {
                metric.outputLong = true;
            }
        }
    }
    int limit = lim != null ? Integer.parseInt(lim) : 1000;
    FieldComparator[] sorts = null;
    if (orders == null || orders.size() == 0) {
        sorts = new FieldComparator[buckets.length];
        for (int i = 0; i < sorts.length; i++) {
            sorts[i] = new FieldComparator("index", ComparatorOrder.ASCENDING);
        }
    } else {
        sorts = getComps(orders);
    }
    int overfetch = (int) (limit * 1.25);
    TupleStream tupleStream = new FacetStream(zkHost, collection, solrParams, buckets, metrics, sorts, overfetch);
    StreamFactory factory = new StreamFactory().withFunctionName("search", CloudSolrStream.class).withFunctionName("parallel", ParallelStream.class).withFunctionName("rollup", RollupStream.class).withFunctionName("sum", SumMetric.class).withFunctionName("min", MinMetric.class).withFunctionName("max", MaxMetric.class).withFunctionName("avg", MeanMetric.class).withFunctionName("count", CountMetric.class).withFunctionName("and", AndEvaluator.class).withFunctionName("or", OrEvaluator.class).withFunctionName("not", NotEvaluator.class).withFunctionName("eq", EqualsEvaluator.class).withFunctionName("val", RawValueEvaluator.class).withFunctionName("gt", GreaterThanEvaluator.class).withFunctionName("lt", LessThanEvaluator.class).withFunctionName("lteq", LessThanEqualToEvaluator.class).withFunctionName("gteq", GreaterThanEqualToEvaluator.class);
    if (havingPredicate != null) {
        BooleanEvaluator booleanOperation = (BooleanEvaluator) factory.constructEvaluator(StreamExpressionParser.parse(havingPredicate));
        tupleStream = new HavingStream(tupleStream, booleanOperation);
    }
    if (lim != null) {
        tupleStream = new LimitStream(tupleStream, limit);
    }
    return tupleStream;
}
Also used : OrEvaluator(org.apache.solr.client.solrj.io.eval.OrEvaluator) EqualsEvaluator(org.apache.solr.client.solrj.io.eval.EqualsEvaluator) GreaterThanEvaluator(org.apache.solr.client.solrj.io.eval.GreaterThanEvaluator) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) BooleanEvaluator(org.apache.solr.client.solrj.io.eval.BooleanEvaluator) LessThanEqualToEvaluator(org.apache.solr.client.solrj.io.eval.LessThanEqualToEvaluator) StreamFactory(org.apache.solr.client.solrj.io.stream.expr.StreamFactory) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)

Aggregations

FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)39 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)30 Tuple (org.apache.solr.client.solrj.io.Tuple)23 Test (org.junit.Test)23 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)21 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)21 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)20 SolrParams (org.apache.solr.common.params.SolrParams)15 FieldEqualitor (org.apache.solr.client.solrj.io.eq.FieldEqualitor)8 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)8 IOException (java.io.IOException)7 ComparatorOrder (org.apache.solr.client.solrj.io.comp.ComparatorOrder)5 MeanMetric (org.apache.solr.client.solrj.io.stream.metrics.MeanMetric)5 MinMetric (org.apache.solr.client.solrj.io.stream.metrics.MinMetric)5 StreamComparator (org.apache.solr.client.solrj.io.comp.StreamComparator)4 MultipleFieldEqualitor (org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor)4 GroupOperation (org.apache.solr.client.solrj.io.ops.GroupOperation)4 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)4 Bucket (org.apache.solr.client.solrj.io.stream.metrics.Bucket)4 CountMetric (org.apache.solr.client.solrj.io.stream.metrics.CountMetric)4