@Override public Document getLatest(String guid, String sensorType) throws IOException { try { Optional<String> index = SolrUtilities .getIndex(config.getIndexSupplier(), sensorType, Optional.empty()); if (!index.isPresent()) { LOG.debug("Unable to find index for sensorType {}", sensorType); return null; } SolrDocument solrDocument = client.getById(index.get(), guid); if (solrDocument == null) { LOG.debug("Unable to find document for sensorType {} and guid {}", sensorType, guid); return null; } return SolrUtilities.toDocument(solrDocument); } catch (SolrServerException e) { throw new IOException(e); } }
@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); } } }
try { SolrDocumentList solrDocumentList = solrClient .getById(METAALERTS_COLLECTION, metaalertGuids, solrParams); Map<String, Document> guidToDocuments = new HashMap<>(); for (SolrDocument doc : solrDocumentList) {
/** * Retrieves the SolrDocument associated with the given identifier. * * @param id the id * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String id) throws SolrServerException, IOException { return getById(null, id, null); }
/** * Retrieves the SolrDocuments associated with the given identifiers. * * If a document was not found, it will not be added to the SolrDocumentList. * * @param ids the ids * * @return a SolrDocumentList, or null if no documents were found * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocumentList getById(Collection<String> ids) throws SolrServerException, IOException { return getById(null, ids); }
/** * Retrieves the SolrDocument associated with the given identifier. * * @param id the id * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String id) throws SolrServerException, IOException { return getById(null, id, null); }
/** * Retrieves the SolrDocument associated with the given identifier. * * @param collection the Solr collection to query * @param id the id * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String collection, String id) throws SolrServerException, IOException { return getById(collection, id, null); } /**
/** * Retrieves the SolrDocument associated with the given identifier and uses * the SolrParams to execute the request. * * @param id the id * @param params additional parameters to add to the query * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String id, SolrParams params) throws SolrServerException, IOException { return getById(null, id, params); }
/** * Retrieves the SolrDocuments associated with the given identifiers. * * If a document was not found, it will not be added to the SolrDocumentList. * * @param collection the Solr collection to query * @param ids the ids * * @return a SolrDocumentList, or null if no documents were found * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocumentList getById(String collection, Collection<String> ids) throws SolrServerException, IOException { return getById(collection, ids, null); }
/** * Retrieves the SolrDocument associated with the given identifier and uses * the SolrParams to execute the request. * * @param id the id * @param params additional parameters to add to the query * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String id, SolrParams params) throws SolrServerException, IOException { return getById(null, id, params); }
/** * Retrieves the SolrDocument associated with the given identifier. * * @param collection the Solr collection to query * @param id the id * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String collection, String id) throws SolrServerException, IOException { return getById(collection, id, null); } /**
/** * Retrieves the SolrDocuments associated with the given identifiers. * * If a document was not found, it will not be added to the SolrDocumentList. * * @param ids the ids * * @return a SolrDocumentList, or null if no documents were found * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocumentList getById(Collection<String> ids) throws SolrServerException, IOException { return getById(null, ids); }
/** * Retrieves the SolrDocuments associated with the given identifiers and uses * the SolrParams to execute the request. * * If a document was not found, it will not be added to the SolrDocumentList. * * @param ids the ids * @param params additional parameters to add to the query * * @return a SolrDocumentList, or null if no documents were found * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocumentList getById(Collection<String> ids, SolrParams params) throws SolrServerException, IOException { return getById(null, ids, params); }
/** * Retrieves the SolrDocuments associated with the given identifiers. * * If a document was not found, it will not be added to the SolrDocumentList. * * @param collection the Solr collection to query * @param ids the ids * * @return a SolrDocumentList, or null if no documents were found * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocumentList getById(String collection, Collection<String> ids) throws SolrServerException, IOException { return getById(collection, ids, null); }
@Override public <T> Collection<T> getByIds(String collection, final Collection<?> ids, final Class<T> clazz) { if (CollectionUtils.isEmpty(ids)) { return Collections.emptyList(); } return execute(solrClient -> convertSolrDocumentListToBeans( solrClient.getById(collection, ids.stream().map(Object::toString).collect(Collectors.toList())), clazz)); }
public static <T extends IsIndexed> List<T> retrieve(SolrClient index, Class<T> classToRetrieve, List<String> id, List<String> fieldsToReturn) throws GenericException { List<T> ret = new ArrayList<>(); try { int block = RodaConstants.DEFAULT_PAGINATION_VALUE; for (int i = 0; i < id.size(); i += block) { List<String> subList = id.subList(i, (i + block <= id.size() ? i + block : id.size())); SolrDocumentList docs = index.getById(SolrCollectionRegistry.getIndexName(classToRetrieve), subList); for (SolrDocument doc : docs) { ret.add(SolrCollectionRegistry.fromSolrDocument(classToRetrieve, doc, fieldsToReturn)); } } } catch (SolrServerException | SolrException | IOException | NotSupportedException e) { throw new GenericException("Could not retrieve object from index", e); } return ret; }
/** * Retrieves the SolrDocument associated with the given identifier and uses * the SolrParams to execute the request. * * @param collection the Solr collection to query * @param id the id * @param params additional parameters to add to the query * * @return retrieved SolrDocument, or null if no document is found. * * @throws IOException If there is a low-level I/O error. * @throws SolrServerException if there is an error on the server */ public SolrDocument getById(String collection, String id, SolrParams params) throws SolrServerException, IOException { SolrDocumentList docs = getById(collection, Collections.singletonList(id), params); if (!docs.isEmpty()) { return docs.get(0); } return null; }
@Override public SearchHit getById(String id) { try { SolrDocument doc = solr.getById(id); SearchHit searchHit = createHitFromDocument(doc); searchHit.setHighlightText(new String[]{getOneValueFromField(doc, this.content)}); return searchHit; } catch (Exception e) { logger.error("Solr getById error.", e); } return null; }
public static SolrInputDocument addOtherPropertiesToIndexedFile(String prefix, OtherMetadata otherMetadataBinary, ModelService model, SolrClient index) throws RequestNotValidException, GenericException, NotFoundException, AuthorizationDeniedException, ParserConfigurationException, SAXException, IOException, XPathExpressionException, SolrServerException { SolrDocument solrDocument = index.getById(RodaConstants.INDEX_FILE, IdUtils.getFileId(otherMetadataBinary.getAipId(), otherMetadataBinary.getRepresentationId(), otherMetadataBinary.getFileDirectoryPath(), otherMetadataBinary.getFileId())); Binary binary = model.retrieveOtherMetadataBinary(otherMetadataBinary); Map<String, List<String>> otherProperties = MetadataFileUtils.parseBinary(binary); for (Map.Entry<String, List<String>> entry : otherProperties.entrySet()) { solrDocument.setField(prefix + entry.getKey(), entry.getValue()); } return solrDocumentToSolrInputDocument(solrDocument); }
public Record get(String collectionName, String id) throws DatastoreClientServiceException { try { SolrDocument document = getClient().getById(collectionName, id); return getConverter().toRecord(document, getUniqueKey(collectionName)); } catch (Exception e) { throw new DatastoreClientServiceException(e); } }