Java Code Examples for org.apache.solr.client.solrj.SolrQuery#addFacetPivotField()

The following examples show how to use org.apache.solr.client.solrj.SolrQuery#addFacetPivotField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractDateRangeFacetQueryConverter.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
@Override
public SolrQuery convert(SOURCE request) {
  SolrQuery solrQuery = new SolrQuery();
  String unit = StringUtils.defaultIfEmpty(request.getUnit(), "+1HOUR");
  solrQuery.setQuery("*:*");
  solrQuery.setFacet(true);
  solrQuery.addFacetPivotField("{!range=r1}" + getTypeFieldName());
  solrQuery.setFacetMinCount(1);
  solrQuery.setFacetLimit(-1);
  solrQuery.setFacetSort(LogSearchConstants.FACET_INDEX);
  solrQuery.add("facet.range", "{!tag=r1}" + getDateFieldName());
  solrQuery.add(String.format(Locale.ROOT, "f.%s.%s", getDateFieldName(), "facet.range.start"), request.getFrom());
  solrQuery.add(String.format(Locale.ROOT, "f.%s.%s", getDateFieldName(), "facet.range.end"), request.getTo());
  solrQuery.add(String.format(Locale.ROOT, "f.%s.%s", getDateFieldName(), "facet.range.gap"), unit);
  solrQuery.remove("sort");
  solrQuery.setRows(0);
  solrQuery.setStart(0);
  return solrQuery;
}
 
Example 2
Source File: DefaultQueryParser.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void appendFacetingOnPivot(SolrQuery solrQuery, FacetQuery query) {
	if (VersionUtil.isSolr3XAvailable()) {
		throw new UnsupportedOperationException(
				"Pivot Facets are not available for solr version lower than 4.x - Please check your depdendencies.");
	}

	FacetOptions facetOptions = query.getFacetOptions();
	String[] pivotFields = convertFieldListToStringArray(facetOptions.getFacetOnPivots());
	solrQuery.addFacetPivotField(pivotFields);
}