當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpSolrServer.add方法代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.impl.HttpSolrServer.add方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpSolrServer.add方法的具體用法?Java HttpSolrServer.add怎麽用?Java HttpSolrServer.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.solr.client.solrj.impl.HttpSolrServer的用法示例。


在下文中一共展示了HttpSolrServer.add方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

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

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

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

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

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

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

示例9: 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.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。