本文整理汇总了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());
}
示例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();
}
}
示例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));
}
示例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();
}
示例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 );
}
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}