Example usage for org.apache.solr.client.solrj SolrClient getById

List of usage examples for org.apache.solr.client.solrj SolrClient getById

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrClient getById.

Prototype

public SolrDocumentList getById(Collection<String> ids, SolrParams params)
        throws SolrServerException, IOException 

Source Link

Document

Retrieves the SolrDocuments associated with the given identifiers and uses the SolrParams to execute the request.

Usage

From source file:com.databasepreservation.visualization.utils.SolrUtils.java

public static <T> T retrieve(SolrClient index, Class<T> classToRetrieve, String id)
        throws NotFoundException, GenericException {
    T ret;/*  www.j ava 2 s  .c  o  m*/
    try {
        SolrDocument doc = index.getById(getIndexName(classToRetrieve), id);
        if (doc != null) {
            ret = solrDocumentTo(classToRetrieve, doc);
        } else {
            throw new NotFoundException("Could not find document " + id);
        }
    } catch (SolrServerException | IOException e) {
        throw new GenericException("Could not retrieve AIP from index", e);
    }
    return ret;
}

From source file:com.databasepreservation.visualization.utils.SolrUtils.java

public static <T> T retrieve(SolrClient index, Class<T> classToRetrieve, String tableUUID, String rowUUID)
        throws NotFoundException, GenericException {
    T ret;/*from  w w w.  ja v a  2 s.  co m*/
    try {
        SolrDocument doc = index.getById(getTableCollectionName(tableUUID), rowUUID);
        if (doc != null) {
            ret = solrDocumentTo(classToRetrieve, doc);
        } else {
            throw new NotFoundException("Could not find document " + rowUUID);
        }
    } catch (SolrServerException | IOException e) {
        throw new GenericException("Could not retrieve AIP from index", e);
    }
    return ret;
}

From source file:org.roda.core.index.utils.SolrUtils.java

public static <T extends IsIndexed> T retrieve(SolrClient index, Class<T> classToRetrieve, String id,
        List<String> fieldsToReturn) throws NotFoundException, GenericException {
    if (id == null) {
        throw new GenericException("Could not retrieve object from a null id");
    }/*  w ww.j a v a  2s . c  o  m*/

    T ret;
    try {
        SolrDocument doc = index.getById(getIndexName(classToRetrieve).get(0), id);
        if (doc != null) {
            ret = solrDocumentTo(classToRetrieve, doc, fieldsToReturn);
        } else {
            throw new NotFoundException("Could not find document " + id);
        }
    } catch (SolrServerException | IOException e) {
        throw new GenericException("Could not retrieve object from index", e);
    }
    return ret;
}

From source file:org.roda.core.index.utils.SolrUtils.java

public static <T extends IsIndexed> List<T> retrieve(SolrClient index, Class<T> classToRetrieve,
        List<String> id, List<String> fieldsToReturn) throws NotFoundException, GenericException {
    List<T> ret = new ArrayList<>();
    try {/*from w ww . j av  a  2 s  .co m*/
        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(getIndexName(classToRetrieve).get(0), subList);
            for (SolrDocument doc : docs) {
                ret.add(solrDocumentTo(classToRetrieve, doc, fieldsToReturn));
            }
        }
    } catch (SolrServerException | IOException e) {
        throw new GenericException("Could not retrieve object from index", e);
    }
    return ret;
}

From source file:org.roda.core.index.utils.SolrUtils.java

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());
    }/*  w w w  .ja va  2 s  .  c  o  m*/
    return solrDocumentToSolrInputDocument(solrDocument);

}

From source file:org.roda.core.index.utils.SolrUtils.java

private static <T extends Serializable> String getObjectLabel(SolrClient index, String className, String id) {
    if (StringUtils.isNotBlank(className) && StringUtils.isNotBlank(id)) {
        try {/*  w  w w .  j  a va2s  .  c o  m*/
            Class<T> objectClass = (Class<T>) Class.forName(className);
            if (objectClass.equals(LiteRODAObject.class)) {
                return null;
            }
            String field = getIndexName(objectClass).get(0);
            SolrDocument doc = index.getById(field, id);
            if (doc != null) {
                if (objectClass.equals(AIP.class)) {
                    return objectToString(doc.get(RodaConstants.AIP_TITLE), null);
                } else if (objectClass.equals(Representation.class)) {
                    return objectToString(doc.get(RodaConstants.REPRESENTATION_ID), null);
                } else if (objectClass.equals(File.class)) {
                    return objectToString(doc.get(RodaConstants.FILE_FILE_ID), null);
                } else if (objectClass.equals(TransferredResource.class)) {
                    return objectToString(doc.get(RodaConstants.TRANSFERRED_RESOURCE_ID), null);
                } else if (objectClass.equals(DIP.class)) {
                    return objectToString(doc.get(RodaConstants.DIP_TITLE), null);
                } else if (objectClass.equals(DIPFile.class)) {
                    return objectToString(doc.get(RodaConstants.DIPFILE_ID), null);
                } else {
                    return objectToString(doc.get(RodaConstants.INDEX_UUID), null);
                }
            }
        } catch (ClassNotFoundException | GenericException | SolrServerException | IOException e) {
            LOGGER.error("Could not return object label of {} {}", className, id, e);
        }
    }

    return null;
}