本文整理匯總了Java中org.apache.solr.client.solrj.impl.HttpSolrServer.commit方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpSolrServer.commit方法的具體用法?Java HttpSolrServer.commit怎麽用?Java HttpSolrServer.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.impl.HttpSolrServer
的用法示例。
在下文中一共展示了HttpSolrServer.commit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testArbitraryJsonIndexing
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
@Test
public void testArbitraryJsonIndexing() throws Exception {
HttpSolrServer server = (HttpSolrServer) getSolrServer();
server.deleteByQuery("*:*");
server.commit();
assertNumFound("*:*", 0); // make sure it got in
// two docs, one with uniqueKey, another without it
String json = "{\"id\":\"abc1\", \"name\": \"name1\"} {\"name\" : \"name2\"}";
HttpClient httpClient = server.getHttpClient();
HttpPost post = new HttpPost(server.getBaseURL() + "/update/json/docs");
post.setHeader("Content-Type", "application/json");
post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1));
HttpResponse response = httpClient.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
server.commit();
assertNumFound("*:*", 2);
}
示例2: addDocs
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerException {
List<SolrInputDocument> docs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
doc.addField("name", solrInstance.name);
docs.add(doc);
}
HttpSolrServer solrServer = new HttpSolrServer(solrInstance.getUrl(), httpClient);
SolrResponseBase resp;
try {
resp = solrServer.add(docs);
assertEquals(0, resp.getStatus());
resp = solrServer.commit();
} finally {
solrServer.shutdown();
}
assertEquals(0, resp.getStatus());
}
示例3: addDocumentsToSolr
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
private void addDocumentsToSolr(List<Map<String,Object>> docs) throws SolrServerException, IOException {
List<SolrInputDocument> sidl = new ArrayList<>();
for (Map<String,Object> doc : docs) {
SolrInputDocument sd = new SolrInputDocument();
for (Entry<String,Object> entry : doc.entrySet()) {
sd.addField(entry.getKey(), entry.getValue());
}
sidl.add(sd);
}
HttpSolrServer solrServer = new HttpSolrServer(getSourceUrl());
try {
solrServer.setConnectionTimeout(15000);
solrServer.setSoTimeout(30000);
solrServer.add(sidl);
solrServer.commit(true, true);
} finally {
solrServer.shutdown();
}
}
示例4: doCommitPerf
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
public void doCommitPerf() throws Exception {
HttpSolrServer client = new HttpSolrServer("http://127.0.0.1:8983/solr");
long start = System.currentTimeMillis();
for (int i=0; i<10000; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", Integer.toString(i % 13));
client.add(doc);
client.commit(true, true, true);
}
long end = System.currentTimeMillis();
client.shutdown();
System.out.println("TIME: " + (end-start));
}
示例5: checkResults
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
private void checkResults(HttpSolrServer server, Queries queries, Indexer idxer) throws InterruptedException {
log.info("Checking if indexes have all the documents they should...");
long totalDocsFound = 0;
for (Map.Entry<String, Long> ent : coreCounts.entrySet()) {
server.setBaseURL(url + ent.getKey());
for (int idx = 0; idx < 3; ++idx) {
try {
server.commit(true, true);
break; // retry loop
} catch (Exception e) {
log.warn("Exception when committing core " + ent.getKey() + " " + e.getMessage());
Thread.sleep(100L);
}
}
long numFound = queries.getCount(server, ent.getKey());
totalDocsFound += numFound;
assertEquals(String.format(Locale.ROOT, "Core %s bad!", ent.getKey()), (long) ent.getValue(), numFound);
}
log.info(String.format(Locale.ROOT, "\n\nDocs indexed (cumulative, all cycles): %,d, total docs: %,d: Cycle stats: updates: %,d: qtimes: %,d",
Indexer.idUnique.get(), totalDocsFound, idxer.getAccumUpdates(), idxer.getAccumQtimes()));
cumulativeDocs += totalDocsFound;
}
示例6: main
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException, SolrServerException {
HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");
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();
}
示例7: clearCollection
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
void clearCollection( ) throws Exception {
try {
HttpSolrServer client = getSolrClient( );
client.deleteByQuery( collection, "*:*" );
client.commit( collection );
}
catch ( Exception e ) {
System.out.println( "Got Exception! " + e );
}
}
示例8: addDocuments
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
void addDocuments( String solrXMLData ) {
try {
List<SolrInputDocument> solrDocs = getSolrInputDocuments( solrXMLData );
HttpSolrServer client = getSolrClient( );
client.add( collection, solrDocs );
client.commit( collection );
}
catch ( Exception e ) {
System.out.println( "Got Exception! " + e );
}
}
示例9: testWithBinaryBean
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
@Test
public void testWithBinaryBean()throws Exception{
HttpSolrServer httpSolrServer = (HttpSolrServer) getSolrServer();
httpSolrServer.setRequestWriter(new BinaryRequestWriter());
httpSolrServer.deleteByQuery( "*:*" ); // delete everything!
final int[] counter = new int[1];
counter[0] = 0;
httpSolrServer.addBeans(new Iterator<Bean>() {
@Override
public boolean hasNext() {
return counter[0] < numdocs;
}
@Override
public Bean next() {
Bean bean = new Bean();
bean.id = "" + (++counter[0]);
bean.cat = "foocat";
return bean;
}
@Override
public void remove() {
//do nothing
}
});
httpSolrServer.commit();
SolrQuery query = new SolrQuery("*:*");
QueryResponse response = httpSolrServer.query(query);
assertEquals(0, response.getStatus());
assertEquals(numdocs, response.getResults().getNumFound());
}
示例10: doIt
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
private void doIt(HttpSolrServer httpSolrServer) throws SolrServerException, IOException {
final int[] counter = new int[1];
counter[0] = 0;
httpSolrServer.add(new Iterator<SolrInputDocument>() {
@Override
public boolean hasNext() {
return counter[0] < numdocs;
}
@Override
public SolrInputDocument next() {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "" + (++counter[0]));
doc.addField("cat", "foocat");
return doc;
}
@Override
public void remove() {
//do nothing
}
});
httpSolrServer.commit();
SolrQuery query = new SolrQuery("*:*");
QueryResponse response = httpSolrServer.query(query);
assertEquals(0, response.getStatus());
assertEquals(numdocs, response.getResults().getNumFound());
}
示例11: createThings
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
@BeforeClass
public static void createThings() throws Exception {
solrHome = createSolrHome();
createJetty(solrHome.getAbsolutePath(), null, null);
String url = jetty.getBaseUrl().toString();
collection1 = new HttpSolrServer(url);
collection2 = new HttpSolrServer(url + "/collection2");
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
shard1 = urlCollection1.replaceAll("https?://", "");
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
collection1.request(req);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
doc.setField("text", "batman");
collection1.add(doc);
collection1.commit();
doc.setField("id", "2");
doc.setField("text", "superman");
collection2.add(doc);
collection2.commit();
}
示例12: createThings
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
@BeforeClass
public static void createThings() throws Exception {
solrHome = createSolrHome();
createJetty(solrHome.getAbsolutePath(), null, null);
String url = jetty.getBaseUrl().toString();
collection1 = new HttpSolrServer(url);
collection2 = new HttpSolrServer(url + "/collection2");
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
shard1 = urlCollection1.replaceAll("https?://", "");
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
collection1.request(req);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
doc.setField("subject", "batman");
doc.setField("title", "foo bar");
collection1.add(doc);
collection1.commit();
doc.setField("id", "2");
doc.setField("subject", "superman");
collection2.add(doc);
collection2.commit();
doc = new SolrInputDocument();
doc.setField("id", "3");
doc.setField("subject", "aquaman");
doc.setField("title", "foo bar");
collection1.add(doc);
collection1.commit();
}
示例13: multiShardTest
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
private void multiShardTest() throws Exception {
// create a collection that has 1 shard and 3 replicas
String testCollectionName = "c8n_2x2_commits";
createCollection(testCollectionName, 2, 2, 1);
cloudClient.setDefaultCollection(testCollectionName);
List<Replica> notLeaders =
ensureAllReplicasAreActive(testCollectionName, "shard1", 2, 2, 30);
assertTrue("Expected 1 replicas for collection " + testCollectionName
+ " but found " + notLeaders.size() + "; clusterState: "
+ printClusterStateInfo(),
notLeaders.size() == 1);
// let's put the leader in it's own partition, no replicas can contact it now
Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard1");
SocketProxy leaderProxy = getProxyForReplica(leader);
leaderProxy.close();
// let's find the leader of shard2 and ask him to commit
Replica shard2Leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard2");
HttpSolrServer server = new HttpSolrServer(ZkCoreNodeProps.getCoreUrl(shard2Leader.getStr("base_url"), shard2Leader.getStr("core")));
server.commit();
Thread.sleep(sleepMsBeforeHealPartition);
cloudClient.getZkStateReader().updateClusterState(true); // get the latest state
leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard1");
assertEquals("Leader was not active", "active", leader.getStr("state"));
leaderProxy.reopen();
Thread.sleep(sleepMsBeforeHealPartition);
// try to clean up
try {
CollectionAdminRequest req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
}
示例14: oneShardTest
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
private void oneShardTest() throws Exception {
// create a collection that has 1 shard and 3 replicas
String testCollectionName = "c8n_1x3_commits";
createCollection(testCollectionName, 1, 3, 1);
cloudClient.setDefaultCollection(testCollectionName);
List<Replica> notLeaders =
ensureAllReplicasAreActive(testCollectionName, "shard1", 1, 3, 30);
assertTrue("Expected 2 replicas for collection " + testCollectionName
+ " but found " + notLeaders.size() + "; clusterState: "
+ printClusterStateInfo(),
notLeaders.size() == 2);
// let's put the leader in it's own partition, no replicas can contact it now
Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard1");
SocketProxy leaderProxy = getProxyForReplica(leader);
leaderProxy.close();
Replica replica = notLeaders.get(0);
HttpSolrServer server = new HttpSolrServer(ZkCoreNodeProps.getCoreUrl(replica.getStr("base_url"), replica.getStr("core")));
server.commit();
Thread.sleep(sleepMsBeforeHealPartition);
cloudClient.getZkStateReader().updateClusterState(true); // get the latest state
leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, "shard1");
assertEquals("Leader was not active", "active", leader.getStr("state"));
leaderProxy.reopen();
Thread.sleep(sleepMsBeforeHealPartition);
// try to clean up
try {
CollectionAdminRequest req = new CollectionAdminRequest.Delete();
req.setCollectionName(testCollectionName);
req.process(cloudClient);
} catch (Exception e) {
// don't fail the test
log.warn("Could not delete collection {} after test completed", testCollectionName);
}
}
示例15: splitByRouteFieldTest
import org.apache.solr.client.solrj.impl.HttpSolrServer; //導入方法依賴的package包/類
public void splitByRouteFieldTest() throws Exception {
log.info("Starting testSplitWithRouteField");
String collectionName = "routeFieldColl";
int numShards = 4;
int replicationFactor = 2;
int maxShardsPerNode = (((numShards * replicationFactor) / getCommonCloudSolrServer()
.getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
HashMap<String, List<Integer>> collectionInfos = new HashMap<>();
CloudSolrServer client = null;
String shard_fld = "shard_s";
try {
client = createCloudClient(null);
Map<String, Object> props = ZkNodeProps.makeMap(
REPLICATION_FACTOR, replicationFactor,
MAX_SHARDS_PER_NODE, maxShardsPerNode,
NUM_SLICES, numShards,
"router.field", shard_fld);
createCollection(collectionInfos, collectionName,props,client);
} finally {
if (client != null) client.shutdown();
}
List<Integer> list = collectionInfos.get(collectionName);
checkForCollection(collectionName, list, null);
waitForRecoveriesToFinish(false);
String url = CustomCollectionTest.getUrlFromZk(getCommonCloudSolrServer().getZkStateReader().getClusterState(), collectionName);
HttpSolrServer collectionClient = new HttpSolrServer(url);
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
final DocRouter router = clusterState.getCollection(collectionName).getRouter();
Slice shard1 = clusterState.getSlice(collectionName, SHARD1);
DocRouter.Range shard1Range = shard1.getRange() != null ? shard1.getRange() : router.fullRange();
final List<DocRouter.Range> ranges = router.partitionRange(2, shard1Range);
final int[] docCounts = new int[ranges.size()];
for (int i = 100; i <= 200; i++) {
String shardKey = "" + (char)('a' + (i % 26)); // See comment in ShardRoutingTest for hash distribution
collectionClient.add(getDoc(id, i, "n_ti", i, shard_fld, shardKey));
int idx = getHashRangeIdx(router, ranges, shardKey);
if (idx != -1) {
docCounts[idx]++;
}
}
for (int i = 0; i < docCounts.length; i++) {
int docCount = docCounts[i];
log.info("Shard {} docCount = {}", "shard1_" + i, docCount);
}
collectionClient.commit();
for (int i = 0; i < 3; i++) {
try {
splitShard(collectionName, SHARD1, null, null);
break;
} catch (HttpSolrServer.RemoteSolrException e) {
if (e.code() != 500) {
throw e;
}
log.error("SPLITSHARD failed. " + (i < 2 ? " Retring split" : ""), e);
if (i == 2) {
fail("SPLITSHARD was not successful even after three tries");
}
}
}
waitForRecoveriesToFinish(collectionName, false);
assertEquals(docCounts[0], collectionClient.query(new SolrQuery("*:*").setParam("shards", "shard1_0")).getResults().getNumFound());
assertEquals(docCounts[1], collectionClient.query(new SolrQuery("*:*").setParam("shards", "shard1_1")).getResults().getNumFound());
collectionClient.shutdown();
}