Example usage for org.apache.solr.common.util JavaBinCodec JavaBinCodec

List of usage examples for org.apache.solr.common.util JavaBinCodec JavaBinCodec

Introduction

In this page you can find the example usage for org.apache.solr.common.util JavaBinCodec JavaBinCodec.

Prototype

public JavaBinCodec(ObjectResolver resolver) 

Source Link

Usage

From source file:org.alfresco.solr.content.SolrContentStore.java

License:Open Source License

/**
 * Retrieve document from SolrContentStore.
 * @param tenant identifier//w  w  w.ja v  a 2 s .com
 * @param dbId identifier
 * @return {@link SolrInputDocument} searched document
 * @throws IOException if error
 */
public SolrInputDocument retrieveDocFromSolrContentStore(String tenant, long dbId) throws IOException {
    String contentUrl = SolrContentUrlBuilder.start().add(SolrContentUrlBuilder.KEY_TENANT, tenant)
            .add(SolrContentUrlBuilder.KEY_DB_ID, String.valueOf(dbId)).get();
    ContentReader reader = this.getReader(contentUrl);
    SolrInputDocument cachedDoc = null;
    if (reader.exists()) {
        // try-with-resources statement closes all these InputStreams
        try (InputStream contentInputStream = reader.getContentInputStream();
                // Uncompresses the document
                GZIPInputStream gzip = new GZIPInputStream(contentInputStream);) {
            cachedDoc = (SolrInputDocument) new JavaBinCodec(resolver).unmarshal(gzip);
        } catch (Exception e) {
            // Don't fail for this
            log.warn("Failed to get doc from store using URL: " + contentUrl, e);
            return null;
        }
    }
    return cachedDoc;
}

From source file:org.alfresco.solr.content.SolrContentStore.java

License:Open Source License

/**
 * Stores a {@link SolrInputDocument} into Alfresco solr content store.
 * @param tenant/*w ww  . jav  a  2s .co  m*/
 * @param dbId
 * @param doc
 * @throws IOException
 */
public void storeDocOnSolrContentStore(String tenant, long dbId, SolrInputDocument doc) throws IOException {
    ContentContext contentContext = SolrContentUrlBuilder.start().add(SolrContentUrlBuilder.KEY_TENANT, tenant)
            .add(SolrContentUrlBuilder.KEY_DB_ID, String.valueOf(dbId)).getContentContext();
    this.delete(contentContext.getContentUrl());
    ContentWriter writer = this.getWriter(contentContext);
    if (log.isDebugEnabled()) {
        log.debug("Writing doc to " + contentContext.getContentUrl());
    }
    try (OutputStream contentOutputStream = writer.getContentOutputStream();
            // Compresses the document
            GZIPOutputStream gzip = new GZIPOutputStream(contentOutputStream);) {
        JavaBinCodec codec = new JavaBinCodec(resolver);
        codec.marshal(doc, gzip);
    } catch (Exception e) {
        // A failure to write to the store is acceptable as long as it's logged
        log.warn("Failed to write to store using URL: " + contentContext.getContentUrl(), e);
    }
}

From source file:org.vootoo.client.netty.NettySolrClientTest.java

License:Apache License

protected static void writeResponse(NamedList<Object> values, OutputStream out) throws IOException {
    JavaBinCodec codec = new JavaBinCodec(new MockResolver());
    codec.marshal(values, out);/*from   w w w.j a v  a 2s .  c  o m*/
}