PublisherSearchRepositorySolrj.java 1.34 KB
package org.legrog.entities;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.IOException;

/*
    Classe implémentant l'interface PublisherSearchRepository avec l'API SolrJ
 */
public class PublisherSearchRepositorySolrj implements PublisherSearchRepository {
    Logger logger = LoggerFactory.getLogger(getClass());

    SolrClient solrClient;

    @Inject
    PublisherSearchRepositorySolrj(SolrClient solrClient) {
        this.solrClient = solrClient;
    }

    //no args constructor to make it proxyable
    PublisherSearchRepositorySolrj() {
    }

    @Override
    public IndexedPublisher save(IndexedPublisher indexedPublisher) throws IndexingException {
        try {
            UpdateResponse updateResponse = solrClient.addBean(indexedPublisher, 1);
            logger.trace("validatePublisherVersion SolrJ UpdateResponse {}", updateResponse);
        } catch (IOException ioe) {
            throw new IndexingException(ioe);
        } catch (SolrServerException sse) {
            logger.error("SolrServerException {}", sse);
            throw new IndexingException(sse.getRootCause());
        }

        return indexedPublisher;
    }
}