本文整理汇总了Java中org.apache.solr.client.solrj.SolrServer.add方法的典型用法代码示例。如果您正苦于以下问题:Java SolrServer.add方法的具体用法?Java SolrServer.add怎么用?Java SolrServer.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.SolrServer
的用法示例。
在下文中一共展示了SolrServer.add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: persistToSolr
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void persistToSolr(Collection<SolrInputDocument> docs) throws SolrServerException, IOException {
if (docs.isEmpty()) {
/**
* @todo Throw an exception here? "DvObject id 9999 does not exist."
*/
logger.info("nothing to persist");
return;
}
logger.fine("persisting to Solr...");
SolrServer solrServer = new HttpSolrServer("http://" + systemConfig.getSolrHostColonPort() + "/solr");
/**
* @todo Do something with these responses from Solr.
*/
UpdateResponse addResponse = solrServer.add(docs);
UpdateResponse commitResponse = solrServer.commit();
}
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:SolrIndexServiceBean.java
示例2: doAtomicUpdate
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
public void doAtomicUpdate() throws Exception {
log.info("### STARTING doAtomicUpdate");
int nClients = clients.size();
assertEquals(8, nClients);
int expectedVal = 0;
for (SolrServer client : clients) {
client.add(sdoc("id", "b!doc", "foo_i", map("inc",1)));
expectedVal++;
QueryResponse rsp = client.query(params("qt","/get", "id","b!doc"));
Object val = ((Map)rsp.getResponse().get("doc")).get("foo_i");
assertEquals((Integer)expectedVal, val);
}
}
示例3: createThumbnailForBook
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
public static void createThumbnailForBook(String solrURL, String solrCore, String bookID) throws SolrServerException, IOException {
SolrServer server = SolrHandler.createConnection(solrURL, solrCore);
QueryResponse response = SolrHandler.searchSolrIndex(server, "id:"+bookID, 1, 0);
List<BookEntry> bookEntries = response.getBeans(BookEntry.class);
System.out.println("Retrieved " + (bookEntries.size()) + " of " + response.getResults().getNumFound());
for(BookEntry bookEntry : bookEntries) {
if (bookEntry.getCover() != null) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Thumbnails.of(new ByteArrayInputStream(bookEntry.getCover()))
.size(130, 200)
.toOutputStream(output);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", bookEntry.getId());
Map<String, Object> thumbnailData = new HashMap<>();
thumbnailData.put("set", output.toByteArray());
doc.addField("thumbnail", thumbnailData);
Map<String, Object> thumbnailStatus = new HashMap<>();
thumbnailStatus.put("set", "done");
doc.addField("thumbnailgenerated", thumbnailStatus);
server.add(doc);
server.commit();
}
}
}
示例4: convertBatchWise
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private static void convertBatchWise(SolrServer server,int batchSize, int offset) throws SolrServerException, IOException {
QueryResponse response = SolrHandler.searchSolrIndex(server, "-thumbnailgenerated:done", batchSize, offset);
List<BookEntry> bookEntries = response.getBeans(BookEntry.class);
System.out.println("Retrieved " + (bookEntries.size() + offset) + " of " + response.getResults().getNumFound());
for(BookEntry bookEntry : bookEntries) {
if (bookEntry.getCover() != null) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
Thumbnails.of(new ByteArrayInputStream(bookEntry.getCover()))
.size(130, 200)
.toOutputStream(output);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", bookEntry.getId());
Map<String, Object> thumbnailData = new HashMap<>();
thumbnailData.put("set", output.toByteArray());
doc.addField("thumbnail", thumbnailData);
Map<String, Object> thumbnailStatus = new HashMap<>();
thumbnailStatus.put("set", "done");
doc.addField("thumbnailgenerated", thumbnailStatus);
server.add(doc);
server.commit();
}
}
response = SolrHandler.searchSolrIndex(server, "-thumbnailgenerated:done", batchSize, offset);
if(response.getResults().getNumFound() > 0) {
convertBatchWise(server, batchSize, 0);
}
}
示例5: doBefore
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
@Before
public void doBefore() throws IOException, SolrServerException {
//add document and commit, and ensure it's there
SolrServer server1 = getSolrServer();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "1234");
server1.add(doc);
server1.commit();
}
示例6: indexDoc
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
/**
* Indexes the document in both the control client, and a randomly selected client
*/
protected void indexDoc(SolrInputDocument doc) throws IOException, SolrServerException {
controlClient.add(doc);
int which = (doc.getField(id).toString().hashCode() & 0x7fffffff) % clients.size();
SolrServer client = clients.get(which);
client.add(doc);
}
示例7: index_specific
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
protected void index_specific(int serverNumber, Object... fields) throws Exception {
SolrInputDocument doc = new SolrInputDocument();
for (int i = 0; i < fields.length; i += 2) {
doc.addField((String) (fields[i]), fields[i + 1]);
}
controlClient.add(doc);
SolrServer client = clients.get(serverNumber);
client.add(doc);
}
示例8: doBefore
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
@Before
public void doBefore() throws IOException, SolrServerException {
//add document and commit, and ensure it's there
SolrServer server1 = getSolrServer();
SolrInputDocument doc = new SolrInputDocument();
doc.addField( "id", "1234" );
server1.add(doc);
server1.commit();
assertTrue(searchFindsIt());
}
示例9: test
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
@Test
public void test() throws SolrServerException, IOException {
TestAgentController.installIfRequired("./target/test-events.json");
assertEquals(0, TestAgentController.getCollectedEventCount());
SolrServerFactory solrServerFactory = new SolrServerFactory();
solrServerFactory.setUrl("file:./target/solr");
solrServerFactory.setEmbeddedSolrConfigurationDir("./src/test/resources/solr");
solrServerFactory.initialize();
SolrServer solrServer = solrServerFactory.getObject();
assertEquals(0, TestAgentController.getCollectedEventCount());
SolrInputDocument solrInputDocument = new SolrInputDocument();
solrInputDocument.setField("id", UUID.randomUUID().toString());
solrInputDocument.setField("timestamp", new Date());
solrServer.add(solrInputDocument);
assertEquals(0, TestAgentController.getCollectedEventCount());
solrServer.commit(true, true);
List<Event> collectedEvents = TestAgentController.getCollectedEvents();
assertEquals(2, collectedEvents.size());
Event event = collectedEvents.get(0);
assertEquals("Embedded Core", getProperty(event.getStringProperties(), "core_name"));
assertEquals("solr/core/commit", event.getType());
event = collectedEvents.get(1);
assertEquals("Embedded Core", getProperty(event.getStringProperties(), "core_name"));
assertEquals("solr/core/new-searcher", event.getType());
solrServerFactory.destroy();
AgentControllerProvider.shutdown();
}
示例10: updateDocument
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
public void updateDocument(List<SolrInputDocument> solrDocs) throws SolrServerException, IOException {
SolrServer solr = bookeryService.getSolrConnection();
solr.add(solrDocs);
solr.commit();
}
示例11: testANewCollectionInOneInstance
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
private void testANewCollectionInOneInstance() throws Exception {
log.info("### STARTING testANewCollectionInOneInstance");
List<SolrServer> collectionClients = new ArrayList<>();
SolrServer client = clients.get(0);
final String baseUrl = ((HttpSolrServer) client).getBaseURL().substring(
0,
((HttpSolrServer) client).getBaseURL().length()
- DEFAULT_COLLECTION.length() - 1);
createCollection(oneInstanceCollection, collectionClients, baseUrl, 1);
createCollection(oneInstanceCollection, collectionClients, baseUrl, 2);
createCollection(oneInstanceCollection, collectionClients, baseUrl, 3);
createCollection(oneInstanceCollection, collectionClients, baseUrl, 4);
while (pending != null && pending.size() > 0) {
Future<Object> future = completionService.take();
if (future == null) return;
pending.remove(future);
}
SolrServer client1 = collectionClients.get(0);
SolrServer client2 = collectionClients.get(1);
SolrServer client3 = collectionClients.get(2);
SolrServer client4 = collectionClients.get(3);
waitForRecoveriesToFinish(oneInstanceCollection, getCommonCloudSolrServer().getZkStateReader(), false);
assertAllActive(oneInstanceCollection, getCommonCloudSolrServer().getZkStateReader());
client2.add(getDoc(id, "1"));
client3.add(getDoc(id, "2"));
client4.add(getDoc(id, "3"));
client1.commit();
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
long oneDocs = client1.query(query).getResults().getNumFound();
long twoDocs = client2.query(query).getResults().getNumFound();
long threeDocs = client3.query(query).getResults().getNumFound();
long fourDocs = client4.query(query).getResults().getNumFound();
query.set("collection", oneInstanceCollection);
query.set("distrib", true);
long allDocs = getCommonCloudSolrServer().query(query).getResults().getNumFound();
// System.out.println("1:" + oneDocs);
// System.out.println("2:" + twoDocs);
// System.out.println("3:" + threeDocs);
// System.out.println("4:" + fourDocs);
// System.out.println("All Docs:" + allDocs);
assertEquals(3, allDocs);
for(SolrServer newCollectionClient:collectionClients) {
newCollectionClient.shutdown();
}
}
示例12: indexDoc
import org.apache.solr.client.solrj.SolrServer; //导入方法依赖的package包/类
protected void indexDoc(String collection, SolrInputDocument doc) throws IOException, SolrServerException {
List<SolrServer> clients = otherCollectionClients.get(collection);
int which = (doc.getField(id).toString().hashCode() & 0x7fffffff) % clients.size();
SolrServer client = clients.get(which);
client.add(doc);
}