use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.
the class FacetStream method open.
public void open() throws IOException {
if (cache != null) {
cloudSolrClient = cache.getCloudSolrClient(zkHost);
} else {
cloudSolrClient = new Builder().withZkHost(zkHost).build();
}
FieldComparator[] adjustedSorts = adjustSorts(buckets, bucketSorts);
String json = getJsonFacetString(buckets, metrics, adjustedSorts, bucketSizeLimit);
ModifiableSolrParams paramsLoc = new ModifiableSolrParams(params);
paramsLoc.set("json.facet", json);
paramsLoc.set("rows", "0");
QueryRequest request = new QueryRequest(paramsLoc);
try {
NamedList response = cloudSolrClient.request(request, collection);
getTuples(response, buckets, metrics);
Collections.sort(tuples, getStreamSort());
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.
the class FacetStream method init.
private void init(String collection, SolrParams params, Bucket[] buckets, FieldComparator[] bucketSorts, Metric[] metrics, int bucketSizeLimit, String zkHost) throws IOException {
this.zkHost = zkHost;
this.params = params;
this.buckets = buckets;
this.metrics = metrics;
this.bucketSizeLimit = bucketSizeLimit;
this.collection = collection;
this.bucketSorts = bucketSorts;
// that they are the same
for (FieldComparator sort : bucketSorts) {
if (sort.hasDifferentFieldNames()) {
throw new IOException("Invalid FacetStream - all sorts must be constructed with a single field name.");
}
}
}
use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.
the class BiJoinStream method createIterationComparator.
private StreamComparator createIterationComparator(StreamEqualitor eq, StreamComparator comp) throws IOException {
if (eq instanceof MultipleFieldEqualitor && comp instanceof MultipleFieldComparator) {
// we know the comp is at least as long as the eq because we've already validated the tuple order
StreamComparator[] compoundComps = new StreamComparator[((MultipleFieldEqualitor) eq).getEqs().length];
for (int idx = 0; idx < compoundComps.length; ++idx) {
StreamEqualitor sourceEqualitor = ((MultipleFieldEqualitor) eq).getEqs()[idx];
StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[idx];
if (sourceEqualitor instanceof FieldEqualitor && sourceComparator instanceof FieldComparator) {
FieldEqualitor fieldEqualitor = (FieldEqualitor) sourceEqualitor;
FieldComparator fieldComparator = (FieldComparator) sourceComparator;
compoundComps[idx] = new FieldComparator(fieldEqualitor.getLeftFieldName(), fieldEqualitor.getRightFieldName(), fieldComparator.getOrder());
} else {
throw new IOException("Failed to create an iteration comparator");
}
}
return new MultipleFieldComparator(compoundComps);
} else if (comp instanceof MultipleFieldComparator) {
StreamEqualitor sourceEqualitor = eq;
StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[0];
if (sourceEqualitor instanceof FieldEqualitor && sourceComparator instanceof FieldComparator) {
FieldEqualitor fieldEqualitor = (FieldEqualitor) sourceEqualitor;
FieldComparator fieldComparator = (FieldComparator) sourceComparator;
return new FieldComparator(fieldEqualitor.getLeftFieldName(), fieldEqualitor.getRightFieldName(), fieldComparator.getOrder());
} else {
throw new IOException("Failed to create an iteration comparator");
}
} else {
StreamEqualitor sourceEqualitor = eq;
StreamComparator sourceComparator = comp;
if (sourceEqualitor instanceof FieldEqualitor && sourceComparator instanceof FieldComparator) {
FieldEqualitor fieldEqualitor = (FieldEqualitor) sourceEqualitor;
FieldComparator fieldComparator = (FieldComparator) sourceComparator;
return new FieldComparator(fieldEqualitor.getLeftFieldName(), fieldEqualitor.getRightFieldName(), fieldComparator.getOrder());
} else {
throw new IOException("Failed to create an iteration comparator");
}
}
}
use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.
the class CloudSolrStream method parseComp.
private StreamComparator parseComp(String sort, String fl) throws IOException {
String[] fls = fl.split(",");
HashSet fieldSet = new HashSet();
for (String f : fls) {
//Handle spaces in the field list.
fieldSet.add(f.trim());
}
String[] sorts = sort.split(",");
StreamComparator[] comps = new StreamComparator[sorts.length];
for (int i = 0; i < sorts.length; i++) {
String s = sorts[i];
//This should take into account spaces in the sort spec.
String[] spec = s.trim().split("\\s+");
if (spec.length != 2) {
throw new IOException("Invalid sort spec:" + s);
}
String fieldName = spec[0].trim();
String order = spec[1].trim();
if (!fieldSet.contains(spec[0])) {
throw new IOException("Fields in the sort spec must be included in the field list:" + spec[0]);
}
// if there's an alias for the field then use the alias
if (null != fieldMappings && fieldMappings.containsKey(fieldName)) {
fieldName = fieldMappings.get(fieldName);
}
comps[i] = new FieldComparator(fieldName, order.equalsIgnoreCase("asc") ? ComparatorOrder.ASCENDING : ComparatorOrder.DESCENDING);
}
if (comps.length > 1) {
return new MultipleFieldComparator(comps);
} else {
return comps[0];
}
}
use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.
the class FacetStream method parseBucketSorts.
private FieldComparator[] parseBucketSorts(String bucketSortString) throws IOException {
String[] sorts = bucketSortString.split(",");
FieldComparator[] comps = new FieldComparator[sorts.length];
for (int i = 0; i < sorts.length; i++) {
String s = sorts[i];
//This should take into account spaces in the sort spec.
String[] spec = s.trim().split("\\s+");
if (2 != spec.length) {
throw new IOException(String.format(Locale.ROOT, "invalid expression - bad bucketSort '%s'. Expected form 'field order'", bucketSortString));
}
String fieldName = spec[0].trim();
String order = spec[1].trim();
comps[i] = new FieldComparator(fieldName, order.equalsIgnoreCase("asc") ? ComparatorOrder.ASCENDING : ComparatorOrder.DESCENDING);
}
return comps;
}
Aggregations