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

The following examples show how to use org.apache.solr.client.solrj.SolrQuery#addFilterQuery() . 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: ServiceLogLevelDateRangeRequestQueryConverter.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
@Override
public SolrQuery convert(ServiceGraphRequest request) {
  SolrQuery solrQuery = super.convert(request);
  addListFilterToSolrQuery(solrQuery, LEVEL, request.getLevel());
  if (request.getHostList() != null && StringUtils.isEmpty(request.getHostName())) {
    List<String> hosts = request.getHostList().length() == 0 ? Arrays.asList("\\-1") : splitValueAsList(request.getHostList(), ",");
    if (hosts.size() > 1) {
      solrQuery.addFilterQuery(String.format("%s:(%s)", HOST, StringUtils.join(hosts, " OR ")));
    } else {
      solrQuery.addFilterQuery(String.format("%s:%s", HOST, hosts.get(0)));
    }
  }
  addListFilterToSolrQuery(solrQuery, CLUSTER, request.getClusters());
  addListFilterToSolrQuery(solrQuery, COMPONENT, request.getMustBe());
  addIncludeFieldValues(solrQuery, request.getIncludeQuery());
  addExcludeFieldValues(solrQuery, request.getExcludeQuery());
  return solrQuery;
}
 
Example 2
Source File: MCRConditionTransformer.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Builds SOLR query.
 * 
 * Automatically builds JOIN-Query if content search fields are used in query.
 * @param sortBy sort criteria
 * @param not true, if all conditions should be negated
 * @param and AND or OR connective between conditions  
 * @param table conditions per "content" or "metadata"
 * @param maxHits maximum hits
 */
@SuppressWarnings("rawtypes")
public static SolrQuery buildMergedSolrQuery(List<MCRSortBy> sortBy, boolean not, boolean and,
    HashMap<String, List<MCRCondition>> table, int maxHits, List<String> returnFields) {
    List<MCRCondition> queryConditions = table.get("metadata");
    MCRCondition combined = buildSubCondition(queryConditions, and, not);
    SolrQuery solrRequestQuery = getSolrQuery(combined, sortBy, maxHits, returnFields);

    for (Map.Entry<String, List<MCRCondition>> mapEntry : table.entrySet()) {
        if (!mapEntry.getKey().equals("metadata")) {
            MCRCondition combinedFilterQuery = buildSubCondition(mapEntry.getValue(), and, not);
            SolrQuery filterQuery = getSolrQuery(combinedFilterQuery, sortBy, maxHits, returnFields);
            solrRequestQuery.addFilterQuery(MCRSolrConstants.SOLR_JOIN_PATTERN + filterQuery.getQuery());
        }
    }
    return solrRequestQuery;
}
 
Example 3
Source File: ItemSearchServiceLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenSearchingWithFilterQuery_thenAllMatchingItemsShouldAvialble() throws Exception {
    itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f);
    itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f);
    itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "Home Appliances", 200f);
    itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing tools and equipment ", 250f);

    SolrQuery query = new SolrQuery();
    query.setQuery("price:[100 TO 300]");
    query.addFilterQuery("description:Brand1", "category:Home Appliances");

    QueryResponse response = solrClient.query(query);
    List<Item> items = response.getBeans(Item.class);

    assertEquals(2, items.size());
}
 
Example 4
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 5
Source File: AbstractOperationHolderConverter.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
public SolrQuery addExcludeFieldValues(SolrQuery query, String fieldValuesMapStr) {
  if (StringUtils.isNotEmpty(fieldValuesMapStr)) {
    List<Map<String, String>> criterias = new Gson().fromJson(fieldValuesMapStr,
      new TypeToken<List<HashMap<String, String>>>(){}.getType());
    for (Map<String, String> criteriaMap : criterias) {
      for (Map.Entry<String, String> fieldEntry : criteriaMap.entrySet()) {
        if (fieldEntry.getKey().equalsIgnoreCase(LOG_MESSAGE)) {
          addLogMessageFilter(query, fieldEntry.getValue(), true);
        } else {
          query.addFilterQuery(String.format("-%s:%s", fieldEntry.getKey(), escapeNonLogMessageField(fieldEntry)));
        }
      }
    }
  }
  return query;
}
 
Example 6
Source File: AbstractOperationHolderConverter.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
public SolrQuery addIncludeFieldValues(SolrQuery query, String fieldValuesMapStr) {
  if (StringUtils.isNotEmpty(fieldValuesMapStr)) {
    List<Map<String, String>> criterias = new Gson().fromJson(fieldValuesMapStr,
      new TypeToken<List<HashMap<String, String>>>(){}.getType());
    for (Map<String, String> criteriaMap : criterias) {
      for (Map.Entry<String, String> fieldEntry : criteriaMap.entrySet()) {
        if (fieldEntry.getKey().equalsIgnoreCase(LOG_MESSAGE)) {
          addLogMessageFilter(query, fieldEntry.getValue(), false);
        } else {
          query.addFilterQuery(String.format("%s:%s", fieldEntry.getKey(), escapeNonLogMessageField(fieldEntry)));
        }
      }
    }
  }
  return query;
}
 
Example 7
Source File: MetadataRequestQueryConverter.java    From ambari-logsearch with Apache License 2.0 6 votes vote down vote up
@Override
public SolrQuery convert(MetadataRequest metadataRequest) {
  SolrQuery metadataQuery = new SolrQuery();
  metadataQuery.setQuery("*:*");
  metadataQuery.addFilterQuery(String.format("%s:%s", TYPE, metadataRequest.getType()));
  if (StringUtils.isNotBlank(metadataRequest.getName())) {
    metadataQuery.addFilterQuery(String.format("%s:%s", NAME, metadataRequest.getName()));
  }

  SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(NAME, SolrQuery.ORDER.asc);
  List<SolrQuery.SortClause> sort = new ArrayList<>();
  sort.add(sortOrder);
  metadataQuery.setRows(10000);
  metadataQuery.setSorts(sort);

  SolrUtil.addListFilterToSolrQuery(metadataQuery, CLUSTER + "_string", metadataRequest.getClusters());

  return metadataQuery;
}
 
Example 8
Source File: AbstractOperationHolderConverter.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
private void addLogMessageFilter(SolrQuery query, String value, boolean negate) {
  String negateToken = negate ? "-" : "";
  value = value.trim();
  if (StringUtils.startsWith(value, "\"") && StringUtils.endsWith(value,"\"")) {
    value = String.format("\"%s\"", SolrUtil.escapeQueryChars(StringUtils.substring(value, 1, -1)));
    query.addFilterQuery(String.format("%s%s:%s", negateToken, LOG_MESSAGE, value));
  }
  else {
    query.addFilterQuery(String.format("%s%s:%s", negateToken, LOG_MESSAGE, SolrUtil.escapeQueryChars(value)));
  }
}
 
Example 9
Source File: ServiceLogsManager.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
public NodeListResponse getTreeExtension(ServiceLogHostComponentRequest request) {
  SimpleFacetQuery facetQuery = conversionService.convert(request, SimpleFacetQuery.class);
  SolrQuery solrQuery = new DefaultQueryParser().doConstructSolrQuery(facetQuery);
  String hostName = request.getHostName() == null ? "" : request.getHostName();
  if (StringUtils.isNotBlank(hostName)){
    solrQuery.addFilterQuery(String.format("%s:*%s*", HOST, hostName));
  }
  QueryResponse response = serviceLogsSolrDao.process(solrQuery, "/service/logs/tree");
  String firstHierarchy = String.format("%s,%s,%s", HOST, COMPONENT, LEVEL);
  String secondHierarchy = String.format("%s,%s", HOST, LEVEL);
  return responseDataGenerator.generateServiceNodeTreeFromFacetResponse(response, firstHierarchy, secondHierarchy,
    LogSearchConstants.HOST, LogSearchConstants.COMPONENT);
}
 
Example 10
Source File: LogLevelFilterManagerSolr.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@Override
public LogLevelFilterMap getLogLevelFilters(String clusterName) {
  LogLevelFilterMap logLevelFilterMap = new LogLevelFilterMap();
  TreeMap<String, LogLevelFilter> logLevelFilterTreeMap = new TreeMap<>();
  try {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    if (useClusterParam) {
      solrQuery.addFilterQuery("cluster_string:" + clusterName);
    }
    solrQuery.addFilterQuery("type:log_level_filter");
    solrQuery.setFields("value", "name");

    final QueryResponse response = solrClient.query(solrQuery);
    if (response != null) {
      final SolrDocumentList documents = response.getResults();
      if (documents != null && !documents.isEmpty()) {
        for(SolrDocument document : documents) {
          String jsons = (String) document.getFieldValue("value");
          String logId = (String) document.getFieldValue("name");
          if (jsons != null) {
            LogLevelFilter logLevelFilter = gson.fromJson(jsons, LogLevelFilter.class);
            logLevelFilterTreeMap.put(logId,logLevelFilter);
          }
        }
      }
    }
  } catch (Exception e) {
    logger.error("Error during getting log level filters: {}", e.getMessage());
  }
  logLevelFilterMap.setFilter(logLevelFilterTreeMap);
  return logLevelFilterMap;
}
 
Example 11
Source File: StandardSearchEngine.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Prepares the query for a search.
 */
protected SolrQuery prepareSearchQuery(String expression, String[] filters, String expressionLanguage,
		Integer rows) {
	SolrQuery query = new SolrQuery();
	query.setQuery(expression);
	query.setSort(SortClause.desc("score"));
	if (rows != null)
		query.setRows(rows);
	if (filters != null)
		query.addFilterQuery(filters);

	query.set("exprLang", expressionLanguage);
	return query;
}
 
Example 12
Source File: SolrOntologySearch.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public ResultsList<OntologyEntryBean> searchOntology(String term, List<String> filters, int start, int rows, List<String> fields) throws SearchEngineException {
	ResultsList<OntologyEntryBean> results = null;
	
	try {
		SolrQuery query = new SolrQuery(term);
		if (filters != null && !filters.isEmpty()) {
			query.addFilterQuery(filters.toArray(new String[filters.size()]));
		}
		if (fields != null && !fields.isEmpty()) {
			query.setFields(fields.toArray(new String[fields.size()]));
		}
		query.setStart(start);
		query.setRows(rows);
		query.setRequestHandler(config.getOntologyRequestHandler());
		
		LOGGER.trace("Ontology search URL: {}", getQueryUrl(query, config.getOntologyUrl()));
		
		QueryResponse response = server.query(query);
		List<OntologyEntryBean> annotations = response.getBeans(OntologyEntryBean.class);
		results = new ResultsList<>(annotations, rows, (start / rows), response.getResults().getNumFound());
	} catch (SolrServerException e) {
		throw new SearchEngineException(e);
	}
	
	return results;
}
 
Example 13
Source File: ServiceLogsManager.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
public ServiceLogResponse getAfterBeforeLogs(ServiceLogTruncatedRequest request) {
  ServiceLogResponse logResponse = new ServiceLogResponse();
  List<ServiceLogData> docList;
  String scrollType = request.getScrollType() != null ? request.getScrollType() : "";

  String logTime = null;
  String sequenceId = null;
  SolrQuery solrQuery = new SolrQuery();
  solrQuery.setQuery("*:*");
  solrQuery.setRows(1);
  solrQuery.addFilterQuery(String.format("%s:%s", ID, request.getId()));
  QueryResponse response = serviceLogsSolrDao.process(solrQuery);
  if (response == null) {
    return logResponse;
  }
  docList = convertToSolrBeans(response);
  if (docList != null && !docList.isEmpty()) {
    Date date = docList.get(0).getLogTime();
    logTime = DateUtil.convertDateWithMillisecondsToSolrDate(date);
    sequenceId = docList.get(0).getSeqNum().toString();
  }
  if (StringUtils.isBlank(logTime)) {
    return logResponse;
  }
  if (LogSearchConstants.SCROLL_TYPE_BEFORE.equals(scrollType) || LogSearchConstants.SCROLL_TYPE_AFTER.equals(scrollType)) {
    ServiceLogResponse beforeAfterResponse = whenScroll(request, logTime, sequenceId, scrollType);
    if (beforeAfterResponse.getLogList() == null) {
      return logResponse;
    }
    List<ServiceLogData> solrDocList = new ArrayList<>(beforeAfterResponse.getLogList());
    logResponse.setLogList(solrDocList);
    return logResponse;

  } else {
    logResponse = new ServiceLogResponse();
    List<ServiceLogData> initial = new ArrayList<>();
    List<ServiceLogData> before = whenScroll(request, logTime, sequenceId, LogSearchConstants.SCROLL_TYPE_BEFORE).getLogList();
    List<ServiceLogData> after = whenScroll(request, logTime, sequenceId, LogSearchConstants.SCROLL_TYPE_AFTER).getLogList();
    if (before != null && !before.isEmpty()) {
      initial.addAll(Lists.reverse(before));
    }
    initial.add(docList.get(0));
    if (after != null && !after.isEmpty()) {
      initial.addAll(after);
    }
    logResponse.setLogList(initial);
    return logResponse;
  }
}
 
Example 14
Source File: FieldInjectorRegistry.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
@Override
public void addFilterConstraint(final SolrQuery query, final String value) {
	query.addFilterQuery(fq(Field.TEXT_OBJECT, value));
}
 
Example 15
Source File: FieldInjectorRegistry.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
@Override
public void addFilterConstraint(final SolrQuery query, final String value) {
	query.addFilterQuery(Field.BOOLEAN_OBJECT + ":" + value);
}
 
Example 16
Source File: FieldInjectorRegistry.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
@Override
public void addFilterConstraint(final SolrQuery query, final String value) {
	query.addFilterQuery(fq(Field.DATE_OBJECT, value));
}
 
Example 17
Source File: SolrDocumentSearch.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
@Override
public ResultsList<Document> searchDocuments(String term, int start, int rows, List<String> additionalFields,
		List<String> filters, FacetStyle facetStyle) throws SearchEngineException {
	ResultsList<Document> results = null;

	try {
		SolrQuery query = new SolrQuery(term);
		query.setStart(start);
		query.setRows(rows);
		query.setRequestHandler(config.getDocumentRequestHandler());
		List<String> queryFields = new ArrayList<>(DEFAULT_SEARCH_FIELDS);
		if (additionalFields != null) {
			queryFields.addAll(additionalFields);
		}
		if (filters != null) {
			query.addFilterQuery(filters.toArray(new String[0]));
		}
		query.setParam(DisMaxParams.QF, queryFields.toArray(new String[queryFields.size()]));
		
		if (facetStyle == FacetStyle.NONE) {
			query.addFacetField(config.getFacetFields().toArray(new String[config.getFacetFields().size()]));
		} else {
			// Add the facet tree params
			query.setFacet(true);
			query.setParam("facet.tree", true);
			query.setParam("facet.tree.field", buildFacetTreeQueryParameter(facetStyle));
		}
		
		LOGGER.debug("Query: {}", query);

		QueryResponse response = server.query(query);
		List<Document> docs;
		long total = 0;
		
		if (response.getGroupResponse() != null) {
			docs = new ArrayList<>(rows);
			GroupResponse gResponse = response.getGroupResponse();
			for (GroupCommand gCommand : gResponse.getValues()) {
				total += gCommand.getNGroups();
				for (Group group : gCommand.getValues()) {
					docs.addAll(server.getBinder().getBeans(Document.class, group.getResult()));
				}
			}
		} else if (response.getResults().getNumFound() == 0) {
			docs = new ArrayList<>();
		} else {
			docs = response.getBeans(Document.class);
			total = response.getResults().getNumFound();
		}
		
		results = new ResultsList<>(docs, start, (start / rows), total, extractFacets(response, facetStyle));
	} catch (SolrServerException e) {
		throw new SearchEngineException(e);
	}

	return results;
}
 
Example 18
Source File: SolrDocumentSearch.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
@Override
public ResultsList<Document> searchDocuments(String term, int start, int rows, List<String> additionalFields,
		List<String> filters) throws SearchEngineException {
	ResultsList<Document> results;

	try {
		SolrQuery query = new SolrQuery(term);
		query.setStart(start);
		query.setRows(rows);
		query.setRequestHandler(config.getDocumentRequestHandler());
		List<String> queryFields = new ArrayList<>(DEFAULT_SEARCH_FIELDS);
		if (additionalFields != null) {
			queryFields.addAll(additionalFields);
		}
		if (filters != null) {
			query.addFilterQuery(filters.toArray(new String[filters.size()]));
		}
		query.setParam(DisMaxParams.QF, queryFields.toArray(new String[queryFields.size()]));
		
		LOGGER.debug("Query: {}", query);

		QueryResponse response = server.query(query);
		List<Document> docs;
		long total = 0;
		
		if (response.getGroupResponse() != null) {
			docs = new ArrayList<>(rows);
			GroupResponse gResponse = response.getGroupResponse();
			for (GroupCommand gCommand : gResponse.getValues()) {
				total += gCommand.getNGroups();
				for (Group group : gCommand.getValues()) {
					docs.addAll(server.getBinder().getBeans(Document.class, group.getResult()));
				}
			}
		} else if (response.getResults().getNumFound() == 0) {
			docs = new ArrayList<>();
		} else {
			docs = response.getBeans(Document.class);
			total = response.getResults().getNumFound();
		}
		
		results = new ResultsList<>(docs, start, (start / rows), total);
	} catch (SolrServerException | IOException e) {
		throw new SearchEngineException(e);
	}

	return results;
}
 
Example 19
Source File: SolrProductSearch.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
/**
 * NOTE: This method is package-private for backward compat only and should not be made public; its interface is subject to change.
 * Client code should call the solrAvailableCategories or solrSideDeepCategory service instead.
 */
static Map<String, Object> getAvailableCategories(DispatchContext dctx, Map<String, Object> context,
        String catalogId, String categoryId, String productId, String facetPrefix, boolean displayProducts, int viewIndex, int viewSize) {
    Map<String, Object> result;

    try {
        HttpSolrClient client = SolrUtil.getQueryHttpSolrClient((String) context.get("core"));
        SolrQuery solrQuery = new SolrQuery();

        String query;
        if (categoryId != null) {
            query = "+cat:"+ SolrExprUtil.escapeTermFull(categoryId);
        } else if (productId != null) {
            query = "+productId:" + SolrExprUtil.escapeTermFull(productId);
        } else {
            query = "*:*";
        }
        solrQuery.setQuery(query);

        if (catalogId != null) {
            solrQuery.addFilterQuery("+catalog:" + SolrExprUtil.escapeTermFull(catalogId));
        }

        SolrQueryUtil.addDefaultQueryFilters(solrQuery, context);
        SolrQueryUtil.addFilterQueries(solrQuery, UtilGenerics.<String>checkList(context.get("queryFilters")));

        if (displayProducts) {
            if (viewSize > -1) {
                solrQuery.setRows(viewSize);
            } else
                solrQuery.setRows(50000);
            if (viewIndex > -1) {
                // 2016-04-01: This must be calculated
                //solrQuery.setStart(viewIndex);
                if (viewSize > 0) {
                    solrQuery.setStart(viewSize * viewIndex);
                }
            }
        } else {
            solrQuery.setFields("cat");
            solrQuery.setRows(0);
        }

        if(UtilValidate.isNotEmpty(facetPrefix)){
            solrQuery.setFacetPrefix(facetPrefix);
        }

        solrQuery.setFacetMinCount(0);
        solrQuery.setFacet(true);
        solrQuery.addFacetField("cat");
        solrQuery.setFacetLimit(-1);
        if (Debug.verboseOn()) Debug.logVerbose("solr: solrQuery: " + solrQuery, module);
        QueryResponse returnMap = client.query(solrQuery, METHOD.POST);
        result = ServiceUtil.returnSuccess();
        result.put("rows", returnMap);
        result.put("numFound", returnMap.getResults().getNumFound());
    } catch (Exception e) {
        Debug.logError(e.getMessage(), module);
        return ServiceUtil.returnError(e.getMessage());
    }
    return result;
}
 
Example 20
Source File: AmbariInfraWithStormLogSearch.java    From streamline with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public LogSearchResult search(LogSearchCriteria logSearchCriteria) {
    SolrQuery query = new SolrQuery();

    query.setQuery(buildColumnAndValue(COLUMN_NAME_LOG_MESSAGE, buildValue(logSearchCriteria.getSearchString())));
    query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_TYPE, COLUMN_VALUE_TYPE_WORKER_LOG));
    query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID, buildValue(logSearchCriteria.getAppId())));
    query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_LOG_TIME, buildDateRangeValue(logSearchCriteria.getFrom(), logSearchCriteria.getTo())));

    List<String> componentNames = logSearchCriteria.getComponentNames();
    if (componentNames != null && !componentNames.isEmpty()) {
        query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME, buildORValues(componentNames)));
    }

    List<String> logLevels = logSearchCriteria.getLogLevels();
    if (logLevels == null || logLevels.isEmpty()) {
        logLevels = DEFAULT_LOG_LEVELS;
    }
    query.addFilterQuery(buildColumnAndValue(COLUMN_NAME_LOG_LEVEL, buildORValues(logLevels)));

    if (logSearchCriteria.getAscending() == null || logSearchCriteria.getAscending()) {
        query.addSort(COLUMN_NAME_LOG_TIME, SolrQuery.ORDER.asc);
    } else {
        query.addSort(COLUMN_NAME_LOG_TIME, SolrQuery.ORDER.desc);
    }

    if (logSearchCriteria.getStart() != null) {
        query.setStart(logSearchCriteria.getStart());
    }
    if (logSearchCriteria.getLimit() != null) {
        query.setRows(logSearchCriteria.getLimit());
    }

    LOG.debug("Querying to Solr: query => {}", query);

    long numFound;
    List<LogSearchResult.LogDocument> results = new ArrayList<>();
    try {
        QueryResponse response = solr.query(query);

        SolrDocumentList docList = response.getResults();
        numFound = docList.getNumFound();

        for (SolrDocument document : docList) {
            String appId = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_TOPOLOGY_ID);
            String componentName = (String) document.getFieldValue(COLUMN_NAME_STREAMLINE_COMPONENT_NAME);
            String logLevel = (String) document.getFieldValue(COLUMN_NAME_LOG_LEVEL);
            String logMessage = (String) document.getFieldValue(COLUMN_NAME_LOG_MESSAGE);
            String host = (String) document.getFieldValue(COLUMN_NAME_HOST);
            String port = (String) document.getFieldValue(COLUMN_NAME_STORM_WORKER_PORT);
            Date logDate = (Date) document.getFieldValue(COLUMN_NAME_LOG_TIME);
            long timestamp = logDate.toInstant().toEpochMilli();

            LogSearchResult.LogDocument logDocument = new LogSearchResult.LogDocument(appId, componentName,
                    logLevel, logMessage, host, port != null ? Integer.parseInt(port) : null, timestamp);
            results.add(logDocument);
        }

    } catch (SolrServerException | IOException e) {
        // TODO: any fine-grained control needed?
        throw new RuntimeException(e);
    }

    return new LogSearchResult(numFound, results);
}