@Override public void accept(GroupCommand comm) { if (groupingField != null && !groupingField.equals(comm.getName())) return; List<Group> groups = comm.getValues(); if (groups != null) { for (Group group : groups) { Consumer<SolrDocument> consumer = consumers.get(group.getGroupValue()); if (consumer != null) group.getResult().forEach(consumer); } } } };
public Collection<Record> query(String queryString, String collectionName) { try { String uniqueKey = getUniqueKey(collectionName); SolrQuery query = new SolrQuery(); query.setQuery(queryString); QueryResponse response = getClient().query(collectionName, query); Collection<Record> results = new ArrayList<>(); response.getResults().forEach(document -> { results.add(getConverter().toRecord(document, uniqueKey)); }); } catch (SolrServerException | IOException e) { logger.error(e.toString()); throw new DatastoreClientServiceException(e); } return null; }
/** * @param query the query in the main index * @param from the field to join from (in the joined index) * @param to the field to join to (in the main index) * @param fromIndex the index to join (if null, join is in main index * @param joinQuery * @param consumer */ public void join(SolrQuery query, String from, String to, String fromIndex, SolrQuery joinQuery, Consumer<SolrDocument> consumer) { if (query == null) throw new NullPointerException("Search query is null"); if (from == null) throw new NullPointerException("from is null"); if (to == null) throw new NullPointerException("to is null"); if (fromIndex == null) throw new NullPointerException("fromIndex is null"); query.setRows(this._row); query.setStart(this._start); // add the filter query String otherIndex = fromIndex == null ? "" : " fromIndex=" + fromIndex; query.addFilterQuery("{!join from=" + from + " to=" + to + otherIndex + "}" + joinQuery.get("q")); LOGGER.info("query {}", query); QueryResponse response = this._solr.query(query); if (response != null) { LOGGER.info("response size {}", response.getResponse().size()); // standard query SolrDocumentList list = response.getResults(); if (list != null) { list.forEach(consumer); } } }
if (list != null) { if (documentConsumer != null) list.forEach(documentConsumer); return new SearchResultsMetadata(query, list.getNumFound(), this._start, this._row);