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


Java HttpSolrServer.commit方法代码示例

本文整理汇总了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);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SolrSchemalessExampleTests.java

示例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());
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestLBHttpSolrServer.java

示例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();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestSolrEntityProcessorEndToEnd.java

示例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));
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestSolrJ.java

示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:OpenCloseCoreStressTest.java

示例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();
}
 
开发者ID:dimensoft,项目名称:improved-journey,代码行数:14,代码来源:SolrjPopulator.java

示例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 );
  }
}
 
开发者ID:detnavillus,项目名称:multifield_suggester_code,代码行数:11,代码来源:MockSolrServer.java

示例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 );
  }
}
 
开发者ID:detnavillus,项目名称:multifield_suggester_code,代码行数:12,代码来源:MockSolrServer.java

示例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());
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:TestBatchUpdate.java

示例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());
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:TestBatchUpdate.java

示例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();
  
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:DistributedDebugComponentTest.java

示例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();
  
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:TestTolerantSearch.java

示例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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:LeaderInitiatedRecoveryOnCommitTest.java

示例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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:42,代码来源:LeaderInitiatedRecoveryOnCommitTest.java

示例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();
}
 
开发者ID:europeana,项目名称:search,代码行数:79,代码来源:ShardSplitTest.java


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