当前位置: 首页>>代码示例>>Java>>正文


Java CloudSolrClient.setDefaultCollection方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.impl.CloudSolrClient.setDefaultCollection方法的典型用法代码示例。如果您正苦于以下问题:Java CloudSolrClient.setDefaultCollection方法的具体用法?Java CloudSolrClient.setDefaultCollection怎么用?Java CloudSolrClient.setDefaultCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.impl.CloudSolrClient的用法示例。


在下文中一共展示了CloudSolrClient.setDefaultCollection方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cloneCloudSolrClient

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
private static SolrClient cloneCloudSolrClient(SolrClient solrClient, String core) {
	if (VersionUtil.isSolr3XAvailable() || solrClient == null) {
		return null;
	}

	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;
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:20,代码来源:SolrClientUtils.java

示例2: getAllIndexedDocs

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public List<Map<String, Object>> getAllIndexedDocs(String collection) {
  List<Map<String, Object>> docs = new ArrayList<>();
  CloudSolrClient solr = miniSolrCloudCluster.getSolrClient();
  solr.setDefaultCollection(collection);
  SolrQuery parameters = new SolrQuery();
  parameters.set("q", "*:*");
  try {
    solr.commit();
    QueryResponse response = solr.query(parameters);
    for (SolrDocument solrDocument : response.getResults()) {
      docs.add(solrDocument);
    }
  } catch (SolrServerException | IOException e) {
    e.printStackTrace();
  }
  return docs;
}
 
开发者ID:apache,项目名称:metron,代码行数:18,代码来源:SolrComponent.java

示例3: setupSolrDocuments

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
private static void setupSolrDocuments() throws SolrServerException, IOException {
	Builder builder = new CloudSolrClient.Builder();
	builder.withZkHost(
			Arrays.asList(new String[] { "192.168.204.181:2181,192.168.204.182:2181,192.168.204.183:2181" }));
	CloudSolrClient client = builder.build();
	client.setDefaultCollection("sql");
	client.deleteByQuery("*:*");
	insertDocument(client, 1, "bluejoe", 38);
	insertDocument(client, 2, "even", 35);
	insertDocument(client, 3, "alex", 8);
	client.commit();
	client.close();
}
 
开发者ID:jenkin2016,项目名称:solr-sql,代码行数:14,代码来源:SolrSqlTest.java

示例4: createCloudSolrWriter

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
private DirectSolrInputDocumentWriter createCloudSolrWriter(Context context, Map<String, String> indexConnectionParams)
        throws IOException {
    String indexZkHost = indexConnectionParams.get(SolrConnectionParams.ZOOKEEPER);
    String collectionName = indexConnectionParams.get(SolrConnectionParams.COLLECTION);

    if (indexZkHost == null) {
        throw new IllegalStateException("No index ZK host defined");
    }

    if (collectionName == null) {
        throw new IllegalStateException("No collection name defined");
    }
    CloudSolrClient solrServer = new CloudSolrClient.Builder().withZkHost(indexZkHost).build();
    int zkSessionTimeout = HBaseIndexerConfiguration.getSessionTimeout(context.getConfiguration());
    solrServer.setZkClientTimeout(zkSessionTimeout);
    solrServer.setZkConnectTimeout(zkSessionTimeout);      
    solrServer.setDefaultCollection(collectionName);

    return new DirectSolrInputDocumentWriter(context.getConfiguration().get(INDEX_NAME_CONF_KEY), solrServer);
}
 
开发者ID:NGDATA,项目名称:hbase-indexer,代码行数:21,代码来源:HBaseIndexerMapper.java

示例5: createSolrClients

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
private Set<SolrClient> createSolrClients(Map<String, String> indexConnectionParams) throws MalformedURLException {
    String solrMode = getSolrMode(indexConnectionParams);
    if (solrMode.equals("cloud")) {
        String indexZkHost = indexConnectionParams.get(SolrConnectionParams.ZOOKEEPER);
        String collectionName = indexConnectionParams.get(SolrConnectionParams.COLLECTION);
        CloudSolrClient solrServer = new CloudSolrClient.Builder().withZkHost(indexZkHost).build();
        int zkSessionTimeout = HBaseIndexerConfiguration.getSessionTimeout(getConf());
        solrServer.setZkClientTimeout(zkSessionTimeout);
        solrServer.setZkConnectTimeout(zkSessionTimeout);
        solrServer.setDefaultCollection(collectionName);
        return Collections.singleton((SolrClient)solrServer);
    } else if (solrMode.equals("classic")) {
        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        connectionManager.setDefaultMaxPerRoute(getSolrMaxConnectionsPerRoute(indexConnectionParams));
        connectionManager.setMaxTotal(getSolrMaxConnectionsTotal(indexConnectionParams));

        HttpClient httpClient = new DefaultHttpClient(connectionManager);
        return new HashSet<SolrClient>(createHttpSolrClients(indexConnectionParams, httpClient));
    } else {
        throw new RuntimeException("Only 'cloud' and 'classic' are valid values for solr.mode, but got " + solrMode);
    }

}
 
开发者ID:NGDATA,项目名称:hbase-indexer,代码行数:24,代码来源:HBaseMapReduceIndexerTool.java

示例6: SolrCloudFixture

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public SolrCloudFixture(String solrHome) throws Exception {
    String xml = IOHelper.loadText(new FileInputStream(new File(solrHome, "solr-no-core.xml")));
    miniCluster = new MiniSolrCloudCluster(1, "/solr", new File("target/tmp").toPath(), xml, null, null);
    String zkAddr = miniCluster.getZkServer().getZkAddress();
    String zkHost = miniCluster.getZkServer().getZkHost();

    buildZooKeeper(zkHost, zkAddr, new File(solrHome), "solrconfig.xml", "schema.xml");
    List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
    for (JettySolrRunner jetty : jettys) {
        if (!jetty.isRunning()) {
            log.warn("JETTY NOT RUNNING!");
        } else {
            log.info("JETTY RUNNING AT " + jetty.getBaseUrl() + " PORT " + jetty.getLocalPort());
        }
    }

    solrClient = new CloudSolrClient(zkAddr, true);
    solrClient.connect();

    createCollection(solrClient, "collection1", 1, 1, "conf1");
    Thread.sleep(1000); // takes some time to setup the collection...
                        // otherwise you'll get no live solr servers
    solrClient.setDefaultCollection("collection1");

    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "1");

    solrClient.add(doc);
    solrClient.commit();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:SolrCloudFixture.java

示例7: FakeRetrySolrServer

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public FakeRetrySolrServer(String zkString, boolean alwaysFail, int retries) {
  CloudSolrClient client  = new CloudSolrClient(zkString);
  client.setDefaultCollection(DEFAULT_COLLECTION);
  client.connect();
  this.delegate = client;
  this.alwaysFail = alwaysFail;
  this.retries = retries;
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:9,代码来源:LucidWorksWriterTest.java

示例8: getSolrClient

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
private SolrClient getSolrClient() throws MalformedURLException {
  if(kerberosAuth) {
    // set kerberos before create SolrClient
    addSecurityProperties();
  }

  if (SolrInstanceAPIType.SINGLE_NODE.toString().equals(this.instanceType)) {
    return new HttpSolrClient.Builder(this.solrURI).build();
  } else {
    CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(this.zookeeperConnect).build();
    cloudSolrClient.setDefaultCollection(this.defaultCollection);
    return cloudSolrClient;
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:15,代码来源:SolrTarget06.java

示例9: build

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/**
 * Builds a {@link LBHttpSolrClient} instance with a default collection name and pointing to a Zookeeper server.
 */
public SolrClient build() {
  checkNotNull(zkHost);
  checkNotNull(defaultCollection);
  // Creates the load-balanced SolrServer.
  CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost);
  cloudSolrClient.setDefaultCollection(defaultCollection);
  if (idField != null) {
    cloudSolrClient.setIdField(idField);
  }
  return cloudSolrClient;
}
 
开发者ID:gbif,项目名称:common-search,代码行数:15,代码来源:CloudSolrServerBuilder.java

示例10: createCloudSolrClient

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
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;
}
 
开发者ID:NGDATA,项目名称:hbase-indexer,代码行数:10,代码来源:SolrClientFactory.java

示例11: getInstance

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
@Override
public SolrClient getInstance() {

    Logger log = LoggerFactory.getLogger(SolrServerProvider.class);

    String host = SearchConfiguration.get(SearchConfiguration.SERVER_HOST);
    //Backwards compatibility
    String solrHost = SearchConfiguration.get(SearchConfiguration.SERVER_SOLR_HOST);
    if(host == null & solrHost != null) {
        host = solrHost;
    }

    if(host == null) {
        log.error("{} has to be set", SearchConfiguration.SERVER_HOST);
        throw new RuntimeException(SearchConfiguration.SERVER_HOST + " has to be set");
    }

    String collection = SearchConfiguration.get(SearchConfiguration.SERVER_COLLECTION);
    //Backwards compatibility
    String solrCollection = SearchConfiguration.get(SearchConfiguration.SERVER_SOLR_COLLECTION);
    if(collection == null & solrCollection != null) {
        collection = solrCollection;
    }

    if(SearchConfiguration.get(SearchConfiguration.SERVER_SOLR_CLOUD, false)) {
        log.info("Instantiating solr cloud client: {}", host);

        if(collection != null) {
            CloudSolrClient client = new CloudSolrClient(host);
            client.setDefaultCollection(collection);
            return client;
        } else {
            log.error(SearchConfiguration.SERVER_COLLECTION + " has to be set");
            throw new RuntimeException(SearchConfiguration.SERVER_COLLECTION + " has to be set");
        }

    } else {

        if(collection != null) {
            host = String.join("/",host,collection);
        }
        log.info("Instantiating solr http client: {}", host);
        return new HttpSolrClient(host);

    }

}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:48,代码来源:RemoteSolrServerProvider.java

示例12: Requester

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public Requester(String collection, int port, String context) {
	cloudSolrClient = new CloudSolrClient("localhost:" + port + context);
	cloudSolrClient.setDefaultCollection(collection);
}
 
开发者ID:BorisNaguet,项目名称:solr-maven-plugin,代码行数:5,代码来源:Requester.java

示例13: getSplits

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
@Override
public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
  this.conf = job;
  boolean isZk = false;
  String connectionUri = job.get(SOLR_ZKHOST);
  String collection = job.get(SOLR_COLLECTION);
  List<String> shards = null;

  if (collection == null) {
    throw new IOException(SOLR_COLLECTION + " not provided or is empty");
  }

  if (connectionUri != null && connectionUri != "") {
    isZk = true;
    CloudSolrClient solrCloud = null;
    try {
      solrCloud = new CloudSolrClient.Builder()
          .withZkHost(connectionUri)
          .build();
      solrCloud.setDefaultCollection(collection);
      solrCloud.connect();
      // first get a list of replicas to query for this collection
      shards = buildShardList(solrCloud, collection);
    } catch (Exception ex) {
      log.warn("Error getting the Shard: " + ex.getMessage());
    } finally {
      if (solrCloud != null) {
        solrCloud.close();
      }
    }

  } else {
    connectionUri = job.get(SOLR_SERVER_URL);
  }

  if (connectionUri == null || connectionUri == "") {
    throw new IOException(SOLR_ZKHOST + " nor " + SOLR_SERVER_URL + " provided or is empty");
  }

  InputSplit[] splits = null;
  if (shards != null) {
    //Create more splits.
    splits = new InputSplit[shards.size()];
    for (int i = 0; i < shards.size(); i++) {
      splits[i] = new LWInputSplit(isZk, true, shards.get(i));
    }
  } else {
    splits = new InputSplit[] { new LWInputSplit(isZk, false, connectionUri) };
  }

  return splits;
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:53,代码来源:LWMapRedInputFormat.java

示例14: init

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
@PostConstruct
public void init() {
  log.info("***** RuleChangeUpdateManager *****");
  // The core Trove indexer doesn't really match the model we have here were all of the domains share worker pools,
  // so this startup pattern will look a little odd to align with that view of the world. This domain will configure
  // and init (via statics) the base class all of the other domains extend. They will wait until we are done.
  BaseWarcDomainManager.setBambooApiBaseUrl(bambooBaseUrl);
  BaseWarcDomainManager.setWorkerCounts(maxFilterWorkers, maxTransformWorkers, maxIndexWorkers);
  // We must acquire the start lock before letting the other domains complete their init() methods.

  log.info("Solr zk path          : {}", zookeeperConfig);
  log.info("Collection            : {}", collection);
  log.info("Number of workers     : {}", NUMBER_OF_WORKERS);
  log.info("Solr read size        : {}", solrReadSize);
  if (disableRulesUpdates) {
    log.warn("!!! Rule updating is currently disabled by configuration");
  }

  client = new CloudSolrClient(zookeeperConfig);
  client.setDefaultCollection(collection);
  format.setTimeZone(TimeZone.getTimeZone("UTC"));
  workProcessor = new WorkProcessor(NUMBER_OF_WORKERS);
  lastProcessed = restrictionsService.getLastProcessed();

  // Typically this doesn't change, but the 'throughput' domain is experimental
  if (useAsyncSolrClient) {
    EndPointRotator.registerNewEndPoint(solrThroughputDomainManager);
  } else {
    EndPointRotator.registerNewEndPoint(solrManager);
  }

  // Find our initial run state
  boolean runNow = false;
  if (restrictionsService.isInRecovery()) {
    // Nest the if test... we are disabled, but we don't want to go down the 'else' branch
    if (!disableRulesUpdates) {
      log.info("Restart into Rule recovery mode.");
      runNow = true;
    }

  } else {
    long oneDayAgo = System.currentTimeMillis() - (24 * 60 * 60 * 1000);
    if (lastProcessed != null && lastProcessed.getAllCompleted() != null
            && lastProcessed.getAllCompleted().getTime() < oneDayAgo) {
      log.info("Restart into Rule processing mode as last check was more that a day ago.");
      runNow = true;
    } else {
      Date nextRun = nextRunDate();
      Schedule.nextRun(this, nextRun);
    }
  }

  // Start running?
  if (runNow && !disableRulesUpdates) {
    startProcessing();
    // wait until the recovery process has had a chance to get the lock
    while (!hasPassedLock) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        // ignore. log at a very low level to avoid IDE objections about empty catch block
        log.trace("Sleep interrupted... sleeping again.", e);
      }
    }
  }
  // Never start this until all the end points are registered
  startMe(filteringService, indexFullText);
}
 
开发者ID:nla,项目名称:bamboo,代码行数:69,代码来源:RuleChangeUpdateManager.java


注:本文中的org.apache.solr.client.solrj.impl.CloudSolrClient.setDefaultCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。