本文整理汇总了Java中org.apache.solr.client.solrj.request.UpdateRequest.add方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequest.add方法的具体用法?Java UpdateRequest.add怎么用?Java UpdateRequest.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.request.UpdateRequest
的用法示例。
在下文中一共展示了UpdateRequest.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexAndCommitOneDocument
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
* Indexiert das übergebene Dokument und übernimmt die Änderungen in den Solr-Index
* durch das Ausführen eines Commits.
*
* @param gutenbergDoc das zu indexierende Dokument
*/
public void indexAndCommitOneDocument(GutenbergDoc gutenbergDoc) {
SolrInputDocument document = buildSolrDoc(gutenbergDoc);
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);
updateRequest.add(document);
updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
try {
updateRequest.process(solrClient);
System.out.println("Dokument " + gutenbergDoc.getDocId() + " erfolgreich indexiert!");
}
catch (SolrServerException|IOException e) {
System.err.println("Fehler bei der Indexierung des Dokuments " + gutenbergDoc.getDocId() + ": " + e.getMessage());
updateRequest.rollback();
}
}
示例2: indexDocumentsAndCommit
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
* Indexiert die übergebene Liste von Dokumenten und führt am Ende ein Commit durch.
*
* Tritt während der Indexierung ein Fehler auf, so werden die Änderungen nicht
* zurückgenommen, die bereits erfolgreich in den Solr-Index geschrieben werden konnten.
*
* @param gutenbergDocs die Liste der zu indexierenden Dokumente
*/
public void indexDocumentsAndCommit(List<GutenbergDoc> gutenbergDocs) {
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);
for (GutenbergDoc gutenbergDoc : gutenbergDocs) {
SolrInputDocument solrInputDocument = buildSolrDoc(gutenbergDoc);
if (gutenbergDoc.getDocId().equals("9")) {
// füge zu Dokument 9 ein Feld hinzu, dass es nicht im Solr-Schema gibt
solrInputDocument.addField("foo", "bar");
}
updateRequest.add(solrInputDocument);
}
updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
try {
updateRequest.process(solrClient);
System.out.println(gutenbergDocs.size() + " Dokumente erfolgreich indexiert!");
}
catch (SolrServerException|IOException e) {
System.err.println("Fehler bei der Indexierung der Dokumente: " + e.getMessage());
updateRequest.rollback();
}
}
示例3: indexAndCommitDocuments
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
* Indexiert die übergebene Liste von Dokumenten und führt nach jedem Dokument einen Commit durch.
*
* Tritt während der Indexierung eines Dokuments ein Fehler auf, so gehen die zuvor bereits
* erfolgreich indexierten Dokumente nicht verloren.
*
* @param gutenbergDocs die Liste der zu indexierenden Dokumente
*/
public void indexAndCommitDocuments(List<GutenbergDoc> gutenbergDocs) {
for (GutenbergDoc gutenbergDoc : gutenbergDocs) {
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);
SolrInputDocument solrInputDocument = buildSolrDoc(gutenbergDoc);
if (gutenbergDoc.getDocId().equals("9")) {
// füge zu Dokument 9 ein Feld hinzu, dass es nicht im Solr-Schema gibt
solrInputDocument.addField("foo", "bar");
}
updateRequest.add(solrInputDocument);
updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
try {
updateRequest.process(solrClient);
System.out.println("Dokument " + gutenbergDoc.getDocId() + " erfolgreich indexiert!");
}
catch (SolrServerException|IOException e) {
System.err.println("Fehler bei der Indexierung der Dokumente: " + e.getMessage());
updateRequest.rollback();
}
}
}
示例4: indexAndCommitOneDocument
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
* Indexiert das übergebene Gutenberg-Dokument und übernimmt die Änderungen in den Solr-Index
* durch das Ausführen eines Commits.
*
* @param gutenbergDoc das zu indexierende Dokument
*/
private void indexAndCommitOneDocument(GutenbergDoc gutenbergDoc) {
SolrInputDocument document = buildSolrDoc(gutenbergDoc);
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
updateRequest.add(document);
updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
try {
updateRequest.process(solrClient);
System.out.println("Dokument " + gutenbergDoc.getDocId() + " erfolgreich indexiert!");
}
catch (SolrServerException|IOException e) {
System.err.println("Fehler bei der Indexierung des Dokuments " + gutenbergDoc.getDocId() + ": " + e.getMessage());
updateRequest.rollback();
}
}
示例5: deleteIndividualFieldsFromIndex
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
private void deleteIndividualFieldsFromIndex(String collectionName, String keyIdField, String docId, HashSet<IndexEntry> fieldDeletions) throws SolrServerException, IOException {
if (fieldDeletions.isEmpty()) return;
Map<String, String> fieldDeletes = new HashMap<String, String>(1) {{ put("set", null); }};
SolrInputDocument doc = new SolrInputDocument();
doc.addField(keyIdField, docId);
StringBuilder sb = new StringBuilder();
for (IndexEntry fieldToDelete : fieldDeletions) {
doc.addField(fieldToDelete.field, fieldDeletes);
sb.append(fieldToDelete).append(",");
}
if (logger.isTraceEnabled())
logger.trace("Deleting individual fields [{}] for document {}", sb.toString(), docId);
UpdateRequest singleDocument = newUpdateRequest();
singleDocument.add(doc);
solrClient.request(singleDocument, collectionName);
}
示例6: deleteIndividualFieldsFromIndex
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
private void deleteIndividualFieldsFromIndex(String collectionName, String keyIdField, String docId, HashSet<IndexEntry> fieldDeletions) throws SolrServerException, IOException {
if (fieldDeletions.isEmpty()) return;
Map<String, String> fieldDeletes = new HashMap<String, String>(1) {{ put("set", null); }};
SolrInputDocument doc = new SolrInputDocument();
doc.addField(keyIdField, docId);
StringBuilder sb = new StringBuilder();
for (IndexEntry fieldToDelete : fieldDeletions) {
doc.addField(fieldToDelete.field, fieldDeletes);
sb.append(fieldToDelete).append(",");
}
if (logger.isTraceEnabled())
logger.trace("Deleting individual fields [{}] for document {}", sb.toString(), docId);
UpdateRequest singleDocument = newUpdateRequest(collectionName);
singleDocument.add(doc);
solrServer.request(singleDocument);
}
示例7: close
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
public void close() throws IOException {
try {
if (!inputDocs.isEmpty()) {
LOG.info("Indexing " + Integer.toString(inputDocs.size()) + " documents");
if (numDeletes > 0) {
LOG.info("Deleting " + Integer.toString(numDeletes) + " documents");
}
UpdateRequest req = new UpdateRequest();
req.add(inputDocs);
req.setParams(params);
req.process(solr);
inputDocs.clear();
}
// solr.commit();
} catch (final SolrServerException e) {
throw makeIOException(e);
}
}
示例8: indexDoc
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,
SolrServerException {
SolrInputDocument doc = new SolrInputDocument();
addFields(doc, fields);
addFields(doc, "rnd_b", true);
controlClient.add(doc);
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
ModifiableSolrParams params = new ModifiableSolrParams();
for (CloudJettyRunner skip : skipServers) {
params.add("test.distrib.skip.servers", skip.url + "/");
}
ureq.setParams(params);
ureq.process(cloudClient);
}
示例9: indexDocumentAndWaitForSync
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
private void indexDocumentAndWaitForSync(String docId) {
final SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", docId);
final UpdateRequest docUpdate = new UpdateRequest();
docUpdate.add(doc);
docUpdate.setParam(UpdateParams.COLLECTION, COLLECTION_NAME);
docUpdate.setWaitSearcher(true);
docUpdate.setParam(UpdateParams.SOFT_COMMIT, Boolean.TRUE.toString());
try {
final UpdateResponse response = docUpdate.process(solrClient);
assertThat(response.getStatus()).isEqualTo(0);
SolrCloudUtils.waitForReplicasToSync(COLLECTION_NAME, solrClient, WAIT_TIMEOUT_SECONDS);
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
}
示例10: indexDocumentAndWaitForSync
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
private void indexDocumentAndWaitForSync(String docId, String collectionName) {
final SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", docId);
final UpdateRequest docUpdate = new UpdateRequest();
docUpdate.add(doc);
docUpdate.setParam(UpdateParams.COLLECTION, collectionName);
docUpdate.setWaitSearcher(true);
docUpdate.setParam(UpdateParams.SOFT_COMMIT, Boolean.TRUE.toString());
try {
final UpdateResponse response = docUpdate.process(solrClient);
assertThat(response.getStatus()).isEqualTo(0);
SolrCloudUtils.waitForReplicasToSync(collectionName, solrClient, WAIT_TIMEOUT_SECONDS);
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
}
示例11: importRecord
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
private static void importRecord(String rec) throws SolrServerException, IOException, JSONException {
// System.out.println(">>> Import a record ");
// JSON record erzeugen ...
JSONObject o = parseJSON(rec);
SolrInputDocument document = new SolrInputDocument();
Iterator k = o.keys();
while (k.hasNext()) {
String key = (String) k.next();
// System.out.println( key + " " + o.get(key).toString() );
document.addField(key, o.get(key).toString());
}
UpdateRequest add = new UpdateRequest();
add.add(document);
add.setCommitWithin(30000);
add.setParam("collection", collection);
add.process(solr);
}
示例12: testChineseDefaults
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
@Test
public void testChineseDefaults() throws Exception {
SolrServer server = getSolrServer();
// Empty the database...
server.deleteByQuery( "*:*" );// delete everything!
server.commit();
assertNumFound( "*:*", 0 ); // make sure it got in
// Beijing medical University
UpdateRequest req = new UpdateRequest();
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "42");
doc.addField("text", "北京医科大学");
req.add(doc);
req.setAction(ACTION.COMMIT, true, true );
req.process( server );
// Beijing university should match:
SolrQuery query = new SolrQuery("北京大学");
QueryResponse rsp = server.query( query );
assertEquals(1, rsp.getResults().getNumFound());
}
示例13: indexDoc
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
@Override
protected void indexDoc(SolrInputDocument doc) throws IOException,
SolrServerException {
controlClient.add(doc);
// if we wanted to randomly pick a client - but sometimes they may be
// down...
// boolean pick = random.nextBoolean();
//
// int which = (doc.getField(id).toString().hashCode() & 0x7fffffff) %
// sliceCount;
//
// if (pick && sliceCount > 1) {
// which = which + ((shardCount / sliceCount) *
// random.nextInt(sliceCount-1));
// }
//
// CommonsHttpSolrServer client = (CommonsHttpSolrServer)
// clients.get(which);
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
// ureq.setParam(UpdateParams.UPDATE_CHAIN, DISTRIB_UPDATE_CHAIN);
ureq.process(cloudClient);
}
示例14: index_specific
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
@Override
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);
HttpSolrServer client = (HttpSolrServer) clients
.get(serverNumber);
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
// ureq.setParam("update.chain", DISTRIB_UPDATE_CHAIN);
ureq.process(client);
}
示例15: index
import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
@Override
public void index() throws IOException, SolrServerException {
LOGGER.info("Sending {} to SOLR...", document.getFieldValue("id"));
UpdateRequest updateRequest = getUpdateRequest(MCRSolrConstants.UPDATE_PATH);
updateRequest.add(document);
updateRequest.process(getSolrClient());
}