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

The following examples show how to use org.apache.solr.client.solrj.SolrQuery#setFacetSort() . 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: ServiceLogsManager.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
public NodeListResponse getHostListByComponent(ServiceLogComponentHostRequest request) {
  SimpleFacetQuery facetQuery = conversionService.convert(request, SimpleFacetQuery.class);
  SolrQuery solrQuery = new DefaultQueryParser().doConstructSolrQuery(facetQuery);
  solrQuery.setFacetSort(request.getSortBy() == null ? HOST: request.getSortBy());

  NodeListResponse list = new NodeListResponse();
  String componentName = request.getComponentName() == null ? "" : request.getComponentName();
  if (StringUtils.isNotBlank(componentName)){
    solrQuery.addFilterQuery(COMPONENT + ":"
      + componentName);
    QueryResponse response = serviceLogsSolrDao.process(solrQuery, "/service/logs/hosts/components");
    String firstHierarchy = String.format("%s,%s,%s", COMPONENT, HOST, LEVEL);
    String secondHierarchy = String.format("%s,%s", COMPONENT, LEVEL);
    return responseDataGenerator.generateServiceNodeTreeFromFacetResponse(response, firstHierarchy, secondHierarchy,
      LogSearchConstants.COMPONENT, LogSearchConstants.HOST);
  } else {
    return list;
  }
}
 
Example 3
Source File: DefaultQueryParser.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private boolean enableFaceting(SolrQuery solrQuery, FacetQuery query) {
	FacetOptions facetOptions = query.getFacetOptions();
	if (facetOptions == null || !facetOptions.hasFacets()) {
		return false;
	}
	solrQuery.setFacet(true);
	solrQuery.setFacetMinCount(facetOptions.getFacetMinCount());
	solrQuery.setFacetLimit(facetOptions.getPageable().getPageSize());
	if (facetOptions.getPageable().getPageNumber() > 0) {
		int offset = Math.max(0, facetOptions.getPageable().getOffset());
		solrQuery.set(FacetParams.FACET_OFFSET, offset);
	}
	if (FacetOptions.FacetSort.INDEX.equals(facetOptions.getFacetSort())) {
		solrQuery.setFacetSort(FacetParams.FACET_SORT_INDEX);
	}
	return true;
}
 
Example 4
Source File: ServiceLogsManager.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
public NodeListResponse getComponentListWithLevelCounts(ServiceLogComponentLevelRequest request) {
  SimpleFacetQuery facetQuery = conversionService.convert(request, SimpleFacetQuery.class);
  SolrQuery solrQuery = new DefaultQueryParser().doConstructSolrQuery(facetQuery);
  solrQuery.setFacetSort(StringUtils.isEmpty(request.getSortBy()) ? COMPONENT: request.getSortBy());
  QueryResponse response = serviceLogsSolrDao.process(facetQuery, "/service/logs/components/levels/counts");
  return responseDataGenerator.generateOneLevelServiceNodeTree(response, String.format("%s,%s", COMPONENT, LEVEL));
}
 
Example 5
Source File: SolrUtil.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
public static void setFacetSort(SolrQuery solrQuery, String sortType) {
  solrQuery.setFacet(true);
  solrQuery.setFacetSort(sortType);
}