Search in sources :

Example 11 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project play-cookbook by spinscale.

the class SolrSearchTest method setup.

@Before
public void setup() throws Exception {
    Fixtures.deleteAllModels();
    server = new CommonsHttpSolrServer("http://localhost:8983/solr");
    server.setRequestWriter(new BinaryRequestWriter());
    clearSolrServerIndex();
    Fixtures.loadModels("test-data.yml");
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) Before(org.junit.Before)

Example 12 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project play-cookbook by spinscale.

the class SolrPlugin method getSearchServer.

public static SolrServer getSearchServer() {
    String url = Play.configuration.getProperty("solr.server", "http://localhost:8983/solr");
    CommonsHttpSolrServer server = null;
    try {
        server = new CommonsHttpSolrServer(url);
        server.setRequestWriter(new BinaryRequestWriter());
    } catch (MalformedURLException e) {
        Logger.error(e, "Problem creating solr server object: %s", e.getMessage());
    }
    return server;
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) MalformedURLException(java.net.MalformedURLException) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter)

Example 13 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project mycore by MyCoRe-Org.

the class MCRSolrCore method setup.

protected void setup(String serverURL, String name) {
    if (!serverURL.endsWith("/")) {
        serverURL += serverURL + "/";
    }
    this.serverURL = serverURL;
    this.name = name;
    String coreURL = serverURL + name;
    int connectionTimeout = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "SolrClient.ConnectionTimeout");
    int socketTimeout = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "SolrClient.SocketTimeout");
    // default server
    solrClient = new HttpSolrClient.Builder(coreURL).withConnectionTimeout(connectionTimeout).withSocketTimeout(socketTimeout).build();
    solrClient.setRequestWriter(new BinaryRequestWriter());
    // concurrent server
    if (USE_CONCURRENT_SERVER) {
        int queueSize = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "ConcurrentUpdateSolrClient.QueueSize");
        int threadCount = MCRConfiguration.instance().getInt(CONFIG_PREFIX + "ConcurrentUpdateSolrClient.ThreadCount");
        concurrentClient = new ConcurrentUpdateSolrClient.Builder(coreURL).withQueueSize(queueSize).withConnectionTimeout(connectionTimeout).withSocketTimeout(socketTimeout).withThreadCount(threadCount).build();
        concurrentClient.setRequestWriter(new BinaryRequestWriter());
    }
    // shutdown handler
    MCRShutdownHandler.getInstance().addCloseable(new MCRShutdownHandler.Closeable() {

        @Override
        public void prepareClose() {
        }

        @Override
        public int getPriority() {
            return Integer.MIN_VALUE + 5;
        }

        @Override
        public void close() {
            shutdown();
        }
    });
}
Also used : MCRShutdownHandler(org.mycore.common.events.MCRShutdownHandler) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter)

Example 14 with BinaryRequestWriter

use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project ranger by apache.

the class SolrMgr method connect.

void connect() {
    if (!initDone) {
        synchronized (lock) {
            if (!initDone) {
                if ("solr".equalsIgnoreCase(rangerBizUtil.getAuditDBType())) {
                    String zkHosts = PropertiesUtil.getProperty(SOLR_ZK_HOSTS);
                    if (zkHosts == null) {
                        zkHosts = PropertiesUtil.getProperty("ranger.audit.solr.zookeeper");
                    }
                    if (zkHosts == null) {
                        zkHosts = PropertiesUtil.getProperty("ranger.solr.zookeeper");
                    }
                    String solrURL = PropertiesUtil.getProperty(SOLR_URLS_PROP);
                    if (solrURL == null) {
                        // Try with url
                        solrURL = PropertiesUtil.getProperty("ranger.audit.solr.url");
                    }
                    if (solrURL == null) {
                        // Let's try older property name
                        solrURL = PropertiesUtil.getProperty("ranger.solr.url");
                    }
                    if (zkHosts != null && !"".equals(zkHosts.trim()) && !"none".equalsIgnoreCase(zkHosts.trim())) {
                        zkHosts = zkHosts.trim();
                        String collectionName = PropertiesUtil.getProperty(SOLR_COLLECTION_NAME);
                        if (collectionName == null || "none".equalsIgnoreCase(collectionName)) {
                            collectionName = DEFAULT_COLLECTION_NAME;
                        }
                        logger.info("Solr zkHosts=" + zkHosts + ", collectionName=" + collectionName);
                        try (Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder()) {
                            // Instantiate
                            SolrHttpClientBuilder kb = krbBuild.getBuilder();
                            HttpClientUtil.setHttpClientBuilder(kb);
                            final List<String> zkhosts = new ArrayList<String>(Arrays.asList(zkHosts.split(",")));
                            CloudSolrClient solrCloudClient = new CloudSolrClient.Builder(zkhosts, Optional.empty()).build();
                            solrCloudClient.setDefaultCollection(collectionName);
                            solrClient = solrCloudClient;
                        } catch (Throwable t) {
                            logger.error("Can't connect to Solr server. ZooKeepers=" + zkHosts + ", collection=" + collectionName, t);
                        }
                    } else {
                        if (solrURL == null || solrURL.isEmpty() || "none".equalsIgnoreCase(solrURL)) {
                            logger.error("Solr ZKHosts and URL for Audit are empty. Please set property " + SOLR_ZK_HOSTS + " or " + SOLR_URLS_PROP);
                        } else {
                            try (Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder()) {
                                SolrHttpClientBuilder kb = krbBuild.getBuilder();
                                HttpClientUtil.setHttpClientBuilder(kb);
                                HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
                                builder.withBaseSolrUrl(solrURL);
                                builder.allowCompression(true);
                                builder.withConnectionTimeout(1000);
                                HttpSolrClient httpSolrClient = builder.build();
                                httpSolrClient.setRequestWriter(new BinaryRequestWriter());
                                solrClient = httpSolrClient;
                                initDone = true;
                            } catch (Throwable t) {
                                logger.error("Can't connect to Solr server. URL=" + solrURL, t);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder) SolrHttpClientBuilder(org.apache.solr.client.solrj.impl.SolrHttpClientBuilder) SolrHttpClientBuilder(org.apache.solr.client.solrj.impl.SolrHttpClientBuilder) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)14 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)7 Test (org.junit.Test)5 BinaryResponseParser (org.apache.solr.client.solrj.impl.BinaryResponseParser)4 ArrayList (java.util.ArrayList)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 CommonsHttpSolrServer (org.apache.solr.client.solrj.impl.CommonsHttpSolrServer)2 ConcurrentUpdateSolrClient (org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient)2 Krb5HttpClientBuilder (org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder)2 SolrHttpClientBuilder (org.apache.solr.client.solrj.impl.SolrHttpClientBuilder)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2 NamedList (org.apache.solr.common.util.NamedList)2 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1