List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient setDefaultCollection
public void setDefaultCollection(String collection)
From source file:com.francelabs.datafari.service.search.SolrServers.java
License:Apache License
public static SolrClient getSolrServer(Core core) throws Exception { // Zookeeper Hosts String solrHosts = ScriptConfiguration.getProperty("SOLRHOSTS"); if (!solrClients.containsKey(core)) { try {//w w w.ja v a 2s . com // TODO : change for ZK ensemble CloudSolrClient solrClient = new CloudSolrClient(solrHosts); solrClient.setDefaultCollection(core.toString()); solrClient.setZkClientTimeout(60000); SolrPing ping = new SolrPing(); solrClient.request(ping); solrClients.put(core, solrClient); } catch (Exception e) { // test default param try { CloudSolrClient solrClient = new CloudSolrClient(defaultURL); solrClient.setDefaultCollection(core.toString()); SolrPing ping = new SolrPing(); solrClient.request(ping); solrClients.put(core, solrClient); } catch (Exception e2) { LOGGER.error("Cannot instanciate Solr Client for core : " + core.toString(), e); throw new Exception("Cannot instanciate Solr Client for core : " + core.toString()); } } } return solrClients.get(core); }
From source file:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java
License:Apache License
private void createCloudClient() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);// 1000 params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);// 5000 params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, timeout); params.set(HttpClientUtil.PROP_SO_TIMEOUT, timeout); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(client); CloudSolrClient cloudSolrClient = new CloudSolrClient(url, lbHttpSolrClient); if (zkClientTimeout != null) { cloudSolrClient.setZkClientTimeout(zkClientTimeout.intValue()); }// w ww . j a va 2 s . co m if (zkConnectTimeout != null) { cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue()); } if (StringUtils.isNoneBlank(collection)) { cloudSolrClient.setDefaultCollection(collection); } cloudSolrClient.connect(); this.setSolrClient(cloudSolrClient); }
From source file:com.frank.search.solr.server.support.SolrClientUtils.java
License:Apache License
private static SolrClient cloneCloudSolrClient(SolrClient solrClient, String core) { if (VersionUtil.isSolr3XAvailable() || solrClient == null) { return null; }/*from ww w .j a v a 2 s. c o m*/ CloudSolrClient cloudServer = (CloudSolrClient) solrClient; String zkHost = readField(solrClient, "zkHost"); Constructor<? extends SolrClient> constructor = (Constructor<? extends SolrClient>) ClassUtils .getConstructorIfAvailable(solrClient.getClass(), String.class, LBHttpSolrClient.class); CloudSolrClient clone = (CloudSolrClient) BeanUtils.instantiateClass(constructor, zkHost, cloneLBHttpSolrClient(cloudServer.getLbClient(), core)); if (org.springframework.util.StringUtils.hasText(core)) { clone.setDefaultCollection(core); } return clone; }
From source file:com.hurence.logisland.service.solr.Solr_5_5_5_ClientService.java
License:Apache License
protected SolrClient createCloudClient(String connectionString, String collection) { CloudSolrClient cloudSolrClient = new CloudSolrClient(connectionString); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(30000); cloudSolrClient.setZkConnectTimeout(30000); return cloudSolrClient; }
From source file:com.hurence.logisland.service.solr.Solr_6_4_2_ChronixClientService.java
License:Apache License
/** * Instantiate Chronix Client. This should be called by subclasses' @OnScheduled method to create a client * if one does not yet exist. If called when scheduled, closeClient() should be called by the subclasses' @OnStopped * method so the client will be destroyed when the processor is stopped. * * @param context The context for this processor * @throws ProcessException if an error occurs while creating an Chronix client */// w w w . java 2 s . c o m protected void createSolrClient(ControllerServiceInitializationContext context) throws ProcessException { if (solr != null) { return; } // create a solr client final boolean isCloud = context.getPropertyValue(SOLR_CLOUD).asBoolean(); final String connectionString = context.getPropertyValue(SOLR_CONNECTION_STRING).asString(); final String collection = context.getPropertyValue(SOLR_COLLECTION).asString(); if (isCloud) { //logInfo("creating solrCloudClient on $solrUrl for collection $collection"); CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(connectionString).build(); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(30000); cloudSolrClient.setZkConnectTimeout(30000); solr = cloudSolrClient; } else { // logInfo(s"creating HttpSolrClient on $solrUrl for collection $collection") solr = new HttpSolrClient.Builder(connectionString + "/" + collection).build(); } }
From source file:com.hurence.logisland.service.solr.Solr_6_6_2_ClientService.java
License:Apache License
@Override protected SolrClient createCloudClient(String connectionString, String collection) { CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(connectionString).build(); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(30000); cloudSolrClient.setZkConnectTimeout(30000); return cloudSolrClient; }
From source file:com.indoqa.solr.spring.client.SolrClientFactory.java
License:Apache License
private void initializeCloudSolrServer() { this.logger.info("Initializing Cloud Solr client with URL: " + this.url); CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder() .withZkHost(CloudSolrServerUrlHelper.getConnectString(this.url)).build(); cloudSolrClient.setDefaultCollection(CloudSolrServerUrlHelper.getCollection(this.url)); cloudSolrClient.connect();/*w w w.j ava2 s .c o m*/ this.solrClient = cloudSolrClient; this.logger.info("Created Cloud Solr client with URL: " + this.url); }
From source file:com.lucidworks.fusion.support.tests.DocumentLevelACP.java
private CloudSolrClient getSolrClient() { CloudSolrClient cloudServer = null; String server = ZOOKEEPER_URL; String collection = DEFAULT_COLLECTION; try {// ww w . ja v a2 s .co m PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); HttpClient client = new DefaultHttpClient(cm); cloudServer = new CloudSolrClient(server, client); cloudServer.setDefaultCollection(collection); System.out.println("CLOUD SERVER INIT OK..."); } catch (Exception e) { e.printStackTrace(); } return cloudServer; }
From source file:com.ngdata.hbaseindexer.indexer.SolrClientFactory.java
License:Apache License
public static SolrClient createCloudSolrClient(Map<String, String> connectionParameters, int zkSessionTimeout) { String solrZk = connectionParameters.get(SolrConnectionParams.ZOOKEEPER); CloudSolrClient solr = new CloudSolrClient.Builder().withZkHost(solrZk).build(); solr.setZkClientTimeout(zkSessionTimeout); solr.setZkConnectTimeout(zkSessionTimeout); String collection = connectionParameters.get(SolrConnectionParams.COLLECTION); solr.setDefaultCollection(collection); return solr;//from w ww . j a va2 s . c o m }
From source file:com.nridge.ds.solr.SolrDS.java
License:Open Source License
/** * Creates a Solr Client instance for use within the SolrJ framework. * This is an advanced method that should not be used for standard * data source operations.//w w w . j a v a2s .co m * * @return Solr client instance. * * @throws DSException Data source related exception. */ public SolrClient createSolrClient() throws DSException { String propertyName; SolrClient solrClient; Logger appLogger = mAppMgr.getLogger(this, "createSolrClient"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); if (StringUtils.isEmpty(mCollectionName)) { propertyName = getCfgPropertyPrefix() + ".collection_name"; mCollectionName = mAppMgr.getString(propertyName); } ArrayList<String> zkHostNameList = new ArrayList<>(); propertyName = getCfgPropertyPrefix() + ".cloud_zk_host_names"; String zookeeperHosts = mAppMgr.getString(propertyName); if (mAppMgr.isPropertyMultiValue(propertyName)) { String[] zkHosts = mAppMgr.getStringArray(propertyName); for (String zkHost : zkHosts) zkHostNameList.add(zkHost); } else { String zkHost = mAppMgr.getString(propertyName); if (StringUtils.isNotEmpty(zkHost)) zkHostNameList.add(zkHost); } if (zkHostNameList.size() > 0) { Optional<String> zkChRoot; propertyName = getCfgPropertyPrefix() + ".cloud_zk_root"; String zkRoot = mAppMgr.getString(propertyName); if (StringUtils.isEmpty(zkRoot)) zkChRoot = Optional.empty(); else zkChRoot = Optional.of(zkRoot); CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder(zkHostNameList, zkChRoot).build(); if (StringUtils.isNotEmpty(mCollectionName)) { mSolrIdentity = String.format("SolrCloud (%s)", mCollectionName); cloudSolrClient.setDefaultCollection(mCollectionName); } propertyName = getCfgPropertyPrefix() + ".cloud_zk_timeout"; int zookeeperTimeout = mAppMgr.getInt(propertyName, Solr.CONNECTION_TIMEOUT_MINIMUM); if (zookeeperTimeout > Solr.CONNECTION_TIMEOUT_MINIMUM) cloudSolrClient.setZkConnectTimeout(zookeeperTimeout); solrClient = cloudSolrClient; mBaseSolrURL = getSolrBaseURL(cloudSolrClient); appLogger.debug(String.format("SolrCloud: %s (%s) - %d connection timeout.", zookeeperHosts, mCollectionName, zookeeperTimeout)); } else { propertyName = getCfgPropertyPrefix() + ".request_uri"; String solrBaseURL = mAppMgr.getString(propertyName); if (StringUtils.isEmpty(solrBaseURL)) { String msgStr = String.format("%s: Property is undefined.", propertyName); throw new DSException(msgStr); } mBaseSolrURL = solrBaseURL; HttpSolrClient.Builder httpSolrClientBuilder = new HttpSolrClient.Builder(solrBaseURL); solrClient = httpSolrClientBuilder.build(); mSolrIdentity = String.format("SolrServer (%s)", solrBaseURL); appLogger.debug(mSolrIdentity); } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); return solrClient; }