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


Java UpdateRequest.add方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:24,代码来源:SolrIndexer.java

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

示例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();
        }
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:32,代码来源:SolrIndexer.java

示例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();
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:24,代码来源:SolrIndexerComplete.java

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

示例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);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:21,代码来源:SolrIndex.java

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

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

示例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);
    }
}
 
开发者ID:shaie,项目名称:lucenelab,代码行数:17,代码来源:MiniSolrCloudClusterTest.java

示例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);
    }
}
 
开发者ID:shaie,项目名称:lucenelab,代码行数:17,代码来源:AutoAddReplicaTest.java

示例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);
    }
 
开发者ID:kamir,项目名称:MorphMiner,代码行数:24,代码来源:ResultLineImporter.java

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

示例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);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:AbstractFullDistribZkTestBase.java

示例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);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:18,代码来源:AbstractFullDistribZkTestBase.java

示例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());
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:8,代码来源:MCRSolrInputDocumentHandler.java


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