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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations