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


Java CloudSolrClient类代码示例

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


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

示例1: getHttpSolrClients

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
/**
 *
 * @param cloudSolrClient
 * @return
 * @throws SolrServerException
 * @throws IOException
 */
private List<HttpSolrClient> getHttpSolrClients(CloudSolrClient cloudSolrClient) throws SolrServerException, IOException {
    List<HttpSolrClient> solrClients = new ArrayList<>();

    for (String baseUrl : getBaseUrls(cloudSolrClient)) {
        NoOpResponseParser responseParser = new NoOpResponseParser();
        responseParser.setWriterType("json");

        HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
        builder.withBaseSolrUrl(baseUrl);

        HttpSolrClient httpSolrClient = builder.build();
        httpSolrClient.setParser(responseParser);

        solrClients.add(httpSolrClient);
    }

    return solrClients;
}
 
开发者ID:mosuka,项目名称:solr-exporter,代码行数:26,代码来源:SolrCollector.java

示例2: testCollectPing

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
@Test
public void testCollectPing() throws Exception {
    String configFile = "conf/config.yml";

    CloudSolrClient cloudSolrClient = cluster.getSolrClient();
    SolrCollectorConfig collectorConfig = new Yaml().loadAs(new FileReader(configFile), SolrCollectorConfig.class);

    SolrCollector collector = new SolrCollector(cloudSolrClient, collectorConfig, 1);
    collector.register(registry);

    // index sample docs
    File exampleDocsDir = new File("src/test/files/solr/example/exampledocs");
    List<File> xmlFiles = Arrays.asList(exampleDocsDir.listFiles((dir, name) -> name.endsWith(".xml")));
    for (File xml : xmlFiles) {
        ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update");
        req.addFile(xml, "application/xml");
        cloudSolrClient.request(req, "collection1");
    }
    cloudSolrClient.commit("collection1");

    collector.collect();

    assertNotEquals(0.0, registry.getSampleValue("solr_scrape_duration_seconds"));

}
 
开发者ID:mosuka,项目名称:solr-exporter,代码行数:26,代码来源:SolrCollectorTest.java

示例3: 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

示例4: 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

示例5: 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

示例6: getCollections

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
/**
 * Get target cores via CollectionsAPI.
 *
 * @param cloudSolrClient
 * @return
 */
public static List<String> getCollections(CloudSolrClient cloudSolrClient) throws SolrServerException, IOException {
    List<String> collections = new ArrayList<>();

    NoOpResponseParser responseParser = new NoOpResponseParser();
    responseParser.setWriterType("json");

    cloudSolrClient.setParser(responseParser);

    CollectionAdminRequest collectionAdminRequest = new CollectionAdminRequest.List();

    NamedList<Object> collectionAdminResponse = cloudSolrClient.request(collectionAdminRequest);

    JsonNode collectionsJsonNode = om.readTree((String) collectionAdminResponse.get("response")).get("collections");

    for (Iterator<JsonNode> i = collectionsJsonNode.iterator(); i.hasNext(); ) {
        String collection = i.next().textValue();
        if (!collections.contains(collection)) {
            collections.add(collection);
        }
    }

    return collections;
}
 
开发者ID:mosuka,项目名称:solr-exporter,代码行数:30,代码来源:SolrCollector.java

示例7: getBaseUrls

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
/**
 * Get base urls via CollectionsAPI.
 *
 * @param cloudSolrClient
 * @return
 */
private List<String> getBaseUrls(CloudSolrClient cloudSolrClient) throws SolrServerException, IOException {
    List<String> baseUrls = new ArrayList<>();

    NoOpResponseParser responseParser = new NoOpResponseParser();
    responseParser.setWriterType("json");

    cloudSolrClient.setParser(responseParser);

    CollectionAdminRequest collectionAdminRequest = new CollectionAdminRequest.ClusterStatus();

    NamedList<Object> collectionAdminResponse = cloudSolrClient.request(collectionAdminRequest);

    List<JsonNode> baseUrlJsonNode = om.readTree((String) collectionAdminResponse.get("response")).findValues("base_url");

    for (Iterator<JsonNode> i = baseUrlJsonNode.iterator(); i.hasNext(); ) {
        String baseUrl = i.next().textValue();
        if (!baseUrls.contains(baseUrl)) {
            baseUrls.add(baseUrl);
        }
    }

    return baseUrls;
}
 
开发者ID:mosuka,项目名称:solr-exporter,代码行数:30,代码来源:SolrCollector.java

示例8: createCollection

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
protected void createCollection(CloudSolrClient cloudSolrClient, String collection) throws Exception {
  CollectionAdminRequest.Create createCmd = new CollectionAdminRequest.Create();
  createCmd.setCollectionName(collection);
  createCmd.setNumShards(numShards);
  createCmd.setConfigName(configName);
  createCmd.setReplicationFactor(replicationFactor);
  int liveNodes = cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes().size();
  int maxShardsPerNode = (int) Math.max(Math.ceil((numShards * replicationFactor) / liveNodes), 1);
  createCmd.setMaxShardsPerNode(maxShardsPerNode);
  log.info("Creating new collection " + collection + " with " + numShards + " shards and " + replicationFactor + " replicas per shard");
  try {
    cloudSolrClient.request(createCmd);
  } catch (Exception exc) {
    // may have been created by another bolt instance
    cloudSolrClient.getZkStateReader().updateClusterState();
    if (!cloudSolrClient.getZkStateReader().getClusterState().hasCollection(collection)) {
      // failed to create the collection and it doesn't exist ... throw the error
      log.error("Failed to create collection "+collection+" due to: "+exc, exc);
      throw exc;
    }
  }
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:23,代码来源:CollectionPerTimeFrameAssignmentStrategy.java

示例9: startCluster

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
@BeforeClass
public static void startCluster() throws Exception {
  File solrXml = new File("src/test/resources/solr.xml");

  tempDir = Files.createTempDirectory("MiniSolrCloudCluster");

  try {
    cluster = new MiniSolrCloudCluster(1, null, tempDir, MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML, null, null);
  } catch (Exception exc) {
    log.error("Failed to initialize a MiniSolrCloudCluster due to: " + exc, exc);
    throw exc;
  }

  cloudSolrClient = new CloudSolrClient(cluster.getZkServer().getZkAddress(), true);
  cloudSolrClient.connect();

  assertTrue(!cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes().isEmpty());
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:19,代码来源:TestSolrCloudClusterSupport.java

示例10: createCollectionIfNotExists

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection)
        throws IOException, SolrServerException, KeeperException, InterruptedException {
    if (!checkIfCollectionExists(client, collection)) {
        Integer numShards = config.get(NUM_SHARDS);
        Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE);
        Integer replicationFactor = config.get(REPLICATION_FACTOR);

        CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create();

        createRequest.setConfigName(collection);
        createRequest.setCollectionName(collection);
        createRequest.setNumShards(numShards);
        createRequest.setMaxShardsPerNode(maxShardsPerNode);
        createRequest.setReplicationFactor(replicationFactor);

        CollectionAdminResponse createResponse = createRequest.process(client);
        if (createResponse.isSuccess()) {
            logger.trace("Collection {} successfully created.", collection);
        } else {
            throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages()));
        }
    }

    waitForRecoveriesToFinish(client, collection);
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:26,代码来源:Solr5Index.java

示例11: getTargetShard

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
private String getTargetShard(Date timestamp) {
    if (!this.isCloud) {
        return null;
    }

    CloudSolrClient cloudSolrClient = (CloudSolrClient) this.solrClient;

    if (System.currentTimeMillis() > this.nextSliceUpdate) {
        this.nextSliceUpdate = System.currentTimeMillis() + SLICE_UPDATE_INTERVAL;
        this.activeSlicesMap = cloudSolrClient
            .getZkStateReader()
            .getClusterState()
            .getCollection(cloudSolrClient.getDefaultCollection())
            .getActiveSlicesMap();
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(timestamp);
    String sliceName = MessageFormat.format("{0,number,0000}-{1,number,00}", calendar.get(YEAR), calendar.get(MONTH) + 1);

    if (this.activeSlicesMap.containsKey(sliceName)) {
        return sliceName;
    }

    return this.fallbackShard;
}
 
开发者ID:Indoqa,项目名称:logspace,代码行数:27,代码来源:SolrEventService.java

示例12: build

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
/**
 * Builds a new SolRDF proxy instance.
 * 
 * @return a new SolRDF proxy instance.
 * @throws UnableToBuildSolRDFClientException in case of build failure.
 */
public SolRDF build() throws UnableToBuildSolRDFClientException {
	if (endpoints.isEmpty()) {
		endpoints.add(DEFAULT_ENDPOINT);
	}

	// FIXME: for DatasetAccessor and (HTTP) query execution service we also need something like LBHttpSolrServer
	final String firstEndpointAddress = endpoints.iterator().next();
	try {
		return new SolRDF(
				DatasetAccessorFactory.createHTTP(
						firstEndpointAddress +
						graphStoreProtocolEndpointPath),
				firstEndpointAddress + sparqlEndpointPath,		
				zkHost != null
					? new CloudSolrClient(zkHost)
					: (endpoints.size() == 1)
						? new HttpSolrClient(endpoints.iterator().next(), httpClient)
						: new LBHttpSolrClient(httpClient, endpoints.toArray(new String[endpoints.size()])));
	} catch (final Exception exception) {
		throw new UnableToBuildSolRDFClientException(exception);
	}	
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:29,代码来源:SolRDF.java

示例13: 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

示例14: 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

示例15: setupBeforeClass

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入依赖的package包/类
@BeforeClass
public static void setupBeforeClass() throws Exception {
    HBASE_TEST_UTILITY.startMiniCluster();
    
    int zkClientPort = HBASE_TEST_UTILITY.getZkCluster().getClientPort();
    
    SOLR_TEST_UTILITY = new SolrTestingUtility(zkClientPort, NetUtils.getFreePort());
    SOLR_TEST_UTILITY.start();
    SOLR_TEST_UTILITY.uploadConfig("config1",
            Resources.toByteArray(Resources.getResource(HBaseMapReduceIndexerToolDirectWriteTest.class, "schema.xml")),
            Resources.toByteArray(Resources.getResource(HBaseMapReduceIndexerToolDirectWriteTest.class, "solrconfig.xml")));
    SOLR_TEST_UTILITY.createCore("collection1_core11", "collection1", "config1", 1);

    COLLECTION = new CloudSolrClient.Builder().withZkHost(SOLR_TEST_UTILITY.getZkConnectString()).build();
    COLLECTION.setDefaultCollection("collection1");
    
    HBASE_ADMIN = ConnectionFactory.createConnection(HBASE_TEST_UTILITY.getConfiguration()).getAdmin();

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


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