@Override public Iterable<Document> getAllLatest(List<GetRequest> getRequests) throws IOException { Collection<String> guids = new HashSet<>(); Collection<String> sensorTypes = new HashSet<>(); for (GetRequest getRequest : getRequests) { guids.add(getRequest.getGuid()); sensorTypes.add(getRequest.getSensorType()); } List<Document> documents = searchByGuids(guids, sensorTypes, hit -> toDocument(hit)); return documents; }
/** * Return the latest version of a document given a GetRequest. * @param request The GetRequest which indicates the GUID and sensor type. * @return Optionally the document (dependent upon existence in the index). * @throws IOException If an error occurs while retrieving the document. */ default Optional<Map<String, Object>> getLatestResult(GetRequest request) throws IOException { Document ret = getLatest(request.getGuid(), request.getSensorType()); if (ret == null) { return Optional.empty(); } else { return Optional.ofNullable(ret.getDocument()); } } }
@Override public Iterable<Document> getAllLatest(List<GetRequest> getRequests) throws IOException { Map<String, Collection<String>> collectionIdMap = new HashMap<>(); for (GetRequest getRequest : getRequests) { Optional<String> index = SolrUtilities .getIndex(config.getIndexSupplier(), getRequest.getSensorType(), getRequest.getIndex()); if (index.isPresent()) { Collection<String> ids = collectionIdMap.getOrDefault(index.get(), new HashSet<>()); ids.add(getRequest.getGuid()); collectionIdMap.put(index.get(), ids); } else { LOG.debug("Unable to find index for sensorType {}", getRequest.getSensorType()); } } try { List<Document> documents = new ArrayList<>(); for (String collection : collectionIdMap.keySet()) { SolrDocumentList solrDocumentList = client.getById(collectionIdMap.get(collection), new SolrQuery().set("collection", collection)); documents.addAll( solrDocumentList.stream().map(SolrUtilities::toDocument).collect(Collectors.toList())); } return documents; } catch (SolrServerException e) { throw new IOException(e); } } }
protected Get buildGet(GetRequest getRequest) throws IOException { Key k = new Key(getRequest.getGuid(), getRequest.getSensorType()); Get get = new Get(Key.toBytes(k)); get.addFamily(cf); return get; }
@Override public Iterable<Document> getAllLatest(List<GetRequest> getRequests) throws IOException { List<Document> documents = new ArrayList<>(); for(Map.Entry<String, List<String>> kv: BACKING_STORE.entrySet()) { for(String doc : kv.getValue()) { Map<String, Object> docParsed = parse(doc); String guid = (String) docParsed.getOrDefault(Constants.GUID, ""); for (GetRequest getRequest: getRequests) { if(getRequest.getGuid().equals(guid)) { documents.add(new Document(doc, guid, getRequest.getSensorType(), 0L)); } } } } return documents; }