本文整理汇总了Java中org.apache.solr.client.solrj.impl.CloudSolrServer类的典型用法代码示例。如果您正苦于以下问题:Java CloudSolrServer类的具体用法?Java CloudSolrServer怎么用?Java CloudSolrServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloudSolrServer类属于org.apache.solr.client.solrj.impl包,在下文中一共展示了CloudSolrServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
public static void main(String[] args) throws MalformedURLException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer solr = new CloudSolrServer(zkHost);
solr.setDefaultCollection(defaultCollection);
/* ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "cat:electronics");
params.set("defType", "edismax");
params.set("start", "0");*/
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例2: main
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
public static void main(String[] args) throws IOException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer server = new CloudSolrServer(zkHost);
server.setDefaultCollection(defaultCollection);
for (int i = 0; i < 1000; ++i) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("cat", "book");
doc.addField("id", "book-" + i);
doc.addField("name", "The Legend of Po part " + i);
server.add(doc);
if (i % 100 == 0)
server.commit(); // periodically flush
}
server.commit();
}
示例3: doTest
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
@Override
public void doTest() throws Exception {
CloudSolrServer client = createCloudClient(null);
try {
createCollection(null, COLLECTION_NAME, 2, 1, 1, client, null, "conf1");
createCollection(null, COLLECTION_NAME1, 1, 1, 1, client, null, "conf1");
} finally {
//remove collections
client.shutdown();
}
listCollection();
clusterStatusNoCollection();
clusterStatusWithCollection();
clusterStatusWithCollectionAndShard();
clusterStatusWithRouteKey();
clusterStatusAliasTest();
clusterStatusRolesTest();
}
示例4: listCollection
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private void listCollection() throws IOException, SolrServerException {
CloudSolrServer client = createCloudClient(null);
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.LIST.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
List<String> collections = (List<String>) rsp.get("collections");
assertTrue("control_collection was not found in list", collections.contains("control_collection"));
assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1));
} finally {
//remove collections
client.shutdown();
}
}
示例5: clusterStatusNoCollection
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private void clusterStatusNoCollection() throws Exception {
CloudSolrServer client = createCloudClient(null);
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(COLLECTION_NAME1));
assertEquals(4, collections.size());
List<String> liveNodes = (List<String>) cluster.get("live_nodes");
assertNotNull("Live nodes should not be null", liveNodes);
assertFalse(liveNodes.isEmpty());
} finally {
//remove collections
client.shutdown();
}
}
示例6: clusterStatusWithCollection
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private void clusterStatusWithCollection() throws IOException, SolrServerException {
CloudSolrServer client = createCloudClient(null);
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", COLLECTION_NAME);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(COLLECTION_NAME));
assertEquals(1, collections.size());
} finally {
//remove collections
client.shutdown();
}
}
示例7: removeAndWaitForReplicaGone
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
protected void removeAndWaitForReplicaGone(String COLL_NAME,
CloudSolrServer client, Replica replica, String shard)
throws SolrServerException, IOException, InterruptedException {
Map m = makeMap("collection", COLL_NAME, "action", DELETEREPLICA, "shard",
shard, "replica", replica.getName());
SolrParams params = new MapSolrParams(m);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
long endAt = System.currentTimeMillis() + 3000;
boolean success = false;
DocCollection testcoll = null;
while (System.currentTimeMillis() < endAt) {
testcoll = getCommonCloudSolrServer().getZkStateReader()
.getClusterState().getCollection(COLL_NAME);
success = testcoll.getSlice(shard).getReplica(replica.getName()) == null;
if (success) {
log.info("replica cleaned up {}/{} core {}",
shard + "/" + replica.getName(), replica.getStr("core"));
log.info("current state {}", testcoll);
break;
}
Thread.sleep(100);
}
assertTrue("Replica not cleaned up", success);
}
示例8: setClusterProp
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
public static boolean setClusterProp(CloudSolrServer client, String name , String val) throws SolrServerException, IOException, InterruptedException {
Map m = makeMap(
"action", CollectionAction.CLUSTERPROP.toLower(),
"name",name);
if(val != null) m.put("val", val);
SolrRequest request = new QueryRequest(new MapSolrParams(m));
request.setPath("/admin/collections");
client.request(request);
long tomeOut = System.currentTimeMillis() + 3000;
boolean changed = false;
while(System.currentTimeMillis() <tomeOut){
Thread.sleep(10);
changed = Objects.equals(val,client.getZkStateReader().getClusterProps().get(name));
if(changed) break;
}
return changed;
}
示例9: createCollection
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private void createCollection(String targetCollection) throws Exception {
HashMap<String, List<Integer>> collectionInfos = new HashMap<>();
CloudSolrServer client = null;
try {
client = createCloudClient(null);
Map<String, Object> props = ZkNodeProps.makeMap(
REPLICATION_FACTOR, 1,
MAX_SHARDS_PER_NODE, 5,
NUM_SLICES, 1);
createCollection(collectionInfos, targetCollection, props, client);
} finally {
if (client != null) client.shutdown();
}
List<Integer> list = collectionInfos.get(targetCollection);
checkForCollection(targetCollection, list, null);
waitForRecoveriesToFinish(targetCollection, false);
}
示例10: createCollectionIfNotExists
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private static void createCollectionIfNotExists(CloudSolrServer server, Configuration config, String collection)
throws IOException, SolrServerException, KeeperException, InterruptedException {
if (!checkIfCollectionExists(server, 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(server);
if (createResponse.isSuccess()) {
logger.trace("Collection {} successfully created.", collection);
} else {
throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages()));
}
}
waitForRecoveriesToFinish(server, collection);
}
示例11: cloneCloudSolrServer
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private static SolrServer cloneCloudSolrServer(SolrServer solrServer, String core) {
if (VersionUtil.isSolr3XAvailable() || solrServer == null) {
return null;
}
CloudSolrServer cloudServer = (CloudSolrServer) solrServer;
String zkHost = readField(solrServer, "zkHost");
Constructor<? extends SolrServer> constructor = (Constructor<? extends SolrServer>) ClassUtils
.getConstructorIfAvailable(solrServer.getClass(), String.class, LBHttpSolrServer.class);
CloudSolrServer clone = (CloudSolrServer) BeanUtils.instantiateClass(constructor, zkHost,
cloneLBHttpSolrServer(cloudServer.getLbServer(), core));
if (org.springframework.util.StringUtils.hasText(core)) {
clone.setDefaultCollection(core);
}
return clone;
}
示例12: testClonesCloudSolrServerForCoreCorrectlyWhenCoreNameIsNotEmpty
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testClonesCloudSolrServerForCoreCorrectlyWhenCoreNameIsNotEmpty() throws MalformedURLException {
LBHttpSolrServer lbSolrServer = new LBHttpSolrServer(BASE_URL, ALTERNATE_BASE_URL);
CloudSolrServer cloudServer = new CloudSolrServer(ZOO_KEEPER_URL, lbSolrServer);
CloudSolrServer clone = SolrServerUtils.clone(cloudServer, CORE_NAME);
Assert.assertEquals(ZOO_KEEPER_URL, ReflectionTestUtils.getField(clone, FIELD_ZOO_KEEPER));
LBHttpSolrServer lbClone = clone.getLbServer();
Map<String, ?> aliveServers = (Map<String, ?>) ReflectionTestUtils.getField(lbClone, FIELD_ALIVE_SERVERS);
Assert.assertThat(aliveServers.keySet(), hasItems(CORE_URL, ALTERNATE_CORE_URL));
assertLBHttpSolrServerProperties(lbSolrServer, lbClone);
Assert.assertThat(clone.getDefaultCollection(), equalTo(CORE_NAME));
}
示例13: createDocsAndQuerySimple
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
/**
* Creates docs as follows and verifies queries work as expected:
* - creates NUM_DOCS documents, where the document id equals the order
* it was created in, starting at 0
* - even-numbered documents get "junit_role" auth token
* - odd-numbered documents get "admin_role" auth token
* - all documents get some bogus auth tokens
* - all documents get a docLevel_role auth token
*/
private void createDocsAndQuerySimple(String collectionName, boolean checkNonAdminUsers) throws Exception {
// ensure no current documents
verifyDeletedocsPass(ADMIN_USER, collectionName, true);
CloudSolrServer server = getCloudSolrServer(collectionName);
try {
DocLevelGenerator generator = new DocLevelGenerator(AUTH_FIELD);
generator.generateDocs(server, NUM_DOCS, "junit_role", "admin_role", EXTRA_AUTH_FIELDS);
querySimple(new QueryRequest(new SolrQuery("*:*")), server, checkNonAdminUsers);
querySimple(getRealTimeGetRequest(), server, checkNonAdminUsers);
} finally {
server.shutdown();
}
}
示例14: deleteByQueryTest
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
/**
* delete the docs as "deleteUser" using deleteByQuery "deleteQueryStr".
* Verify that number of docs returned for "queryUser" equals
* "expectedQueryDocs" after deletion.
*/
private void deleteByQueryTest(String collectionName, String deleteUser,
String deleteByQueryStr, String queryUser, int expectedQueryDocs) throws Exception {
createDocsAndQuerySimple(collectionName, true);
CloudSolrServer server = getCloudSolrServer(collectionName);
try {
setAuthenticationUser(deleteUser);
server.deleteByQuery(deleteByQueryStr);
server.commit();
checkDeleteByQuery(new QueryRequest(new SolrQuery("*:*")), server,
queryUser, expectedQueryDocs);
checkDeleteByQuery(getRealTimeGetRequest(), server,
queryUser, expectedQueryDocs);
} finally {
server.shutdown();
}
}
示例15: deleteByIdTest
import org.apache.solr.client.solrj.impl.CloudSolrServer; //导入依赖的package包/类
private void deleteByIdTest(String collectionName) throws Exception {
createDocsAndQuerySimple(collectionName, true);
CloudSolrServer server = getCloudSolrServer(collectionName);
try {
setAuthenticationUser("junit");
List<String> allIds = new ArrayList<String>(NUM_DOCS);
for (int i = 0; i < NUM_DOCS; ++i) {
allIds.add(Long.toString(i));
}
server.deleteById(allIds);
server.commit();
checkDeleteById(new QueryRequest(new SolrQuery("*:*")), server);
checkDeleteById(getRealTimeGetRequest(), server);
} finally {
server.shutdown();
}
}