Search in sources :

Example 1 with ComparatorOrder

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

the class SolrTable method adjustSorts.

private StreamComparator[] adjustSorts(List<Pair<String, String>> orders, Bucket[] buckets) throws IOException {
    List<FieldComparator> adjustedSorts = new ArrayList();
    Set<String> bucketFields = new HashSet();
    Set<String> sortFields = new HashSet();
    ComparatorOrder comparatorOrder = ComparatorOrder.ASCENDING;
    for (Pair<String, String> order : orders) {
        sortFields.add(order.getKey());
        adjustedSorts.add(new FieldComparator(order.getKey(), ascDescComp(order.getValue())));
        comparatorOrder = ascDescComp(order.getValue());
    }
    for (Bucket bucket : buckets) {
        bucketFields.add(bucket.toString());
    }
    for (String sf : sortFields) {
        if (!bucketFields.contains(sf)) {
            throw new IOException("All sort fields must be in the field list.");
        }
    }
    //Add sort fields if needed
    if (sortFields.size() < buckets.length) {
        for (Bucket bucket : buckets) {
            String b = bucket.toString();
            if (!sortFields.contains(b)) {
                adjustedSorts.add(new FieldComparator(bucket.toString(), comparatorOrder));
            }
        }
    }
    return adjustedSorts.toArray(new FieldComparator[adjustedSorts.size()]);
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) IOException(java.io.IOException) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder)

Example 2 with ComparatorOrder

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

the class SolrTable method getComps.

private static FieldComparator[] getComps(List<Pair<String, String>> orders) {
    FieldComparator[] comps = new FieldComparator[orders.size()];
    for (int i = 0; i < orders.size(); i++) {
        Pair<String, String> sortItem = orders.get(i);
        String ordering = sortItem.getValue();
        ComparatorOrder comparatorOrder = ascDescComp(ordering);
        String sortKey = sortItem.getKey();
        comps[i] = new FieldComparator(sortKey, comparatorOrder);
    }
    return comps;
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder)

Example 3 with ComparatorOrder

use of org.apache.solr.client.solrj.io.comp.ComparatorOrder 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 4 with ComparatorOrder

use of org.apache.solr.client.solrj.io.comp.ComparatorOrder 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 5 with ComparatorOrder

use of org.apache.solr.client.solrj.io.comp.ComparatorOrder 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)

Aggregations

ComparatorOrder (org.apache.solr.client.solrj.io.comp.ComparatorOrder)5 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)5 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)5 IOException (java.io.IOException)1