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


Java UpdateResponse類代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.response.UpdateResponse的典型用法代碼示例。如果您正苦於以下問題:Java UpdateResponse類的具體用法?Java UpdateResponse怎麽用?Java UpdateResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UpdateResponse類屬於org.apache.solr.client.solrj.response包,在下文中一共展示了UpdateResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: persistToSolr

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的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: indexMap

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
public void indexMap(String id, Map<String, List<String>> objectMap)
   throws IOException, SolrServerException {
    SolrInputDocument document = new SolrInputDocument();
    document.addField("id", id);
    for (String key : objectMap.keySet()) {
        Object value = objectMap.get(key);
        if (value != null) {
            // System.err.printf("%s: class: %s\n", key, value.getClass());
            document.addField(key + "_ss", value);
        }
    }

    try {
        UpdateResponse response = solr.add(document);
        // solr.commit();
    } catch (HttpSolrClient.RemoteSolrException ex) {
        System.err.printf("document: %s", document);
        System.err.printf("Commit exception: %s\n", ex.getMessage());
    }
}
 
開發者ID:pkiraly,項目名稱:metadata-qa-marc,代碼行數:21,代碼來源:MarcSolrClient.java

示例3: indexDuplumKey

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
public void indexDuplumKey(String id, Map<String, Object> objectMap)
        throws IOException, SolrServerException {
    SolrInputDocument document = new SolrInputDocument();
    document.addField("id", id);
    for (String key : objectMap.keySet()) {
        Object value = objectMap.get(key);
        if (value != null) {
            // System.err.printf("%s: class: %s\n", key, value.getClass());
            document.addField(key + "_ss", value);
        }
    }

    try {
        UpdateResponse response = solr.add(document);
        // solr.commit();
    } catch (HttpSolrClient.RemoteSolrException ex) {
        System.err.printf("document: %s", document);
        System.err.printf("Commit exception: %s\n", ex.getMessage());
    }
}
 
開發者ID:pkiraly,項目名稱:metadata-qa-marc,代碼行數:21,代碼來源:MarcSolrClient.java

示例4: deleteIndex

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
@Override
public synchronized void deleteIndex(BaseSearchBean bean) throws Exception {
    if (bean == null) {
        logger.warn("Get search bean is empty!");
        return;
    }

    String id = bean.getId();

    if (StringUtils.isEmpty(id)) {
        logger.warn("get id and id value from bean is empty!");
        return;
    }

    UpdateResponse response = solrClient.deleteById(id);
    solrClient.commit();

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("delete id '%s', result: '%d' Qtime: '%d'", id, response.getStatus(), response.getQTime()));
    }
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:22,代碼來源:SolrSearchEngine.java

示例5: updateDocs

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
private void updateDocs( List<SolrInputDocument> docs, boolean commit ) throws SolrServerException, IOException {
  LOG.debug( "updateDocs " + docs.size( ) );
  SolrClient suggestClient = getSuggestClient( );
  try {
    UpdateResponse resp = suggestClient.add( suggesterCollection, docs );
  }
  catch ( SolrServerException sse ) {
    LOG.error( "Got SolrServerExeption " + sse );
    throw sse;
  }
    
  if (commit) {
    LOG.debug( "committing to " + suggestHost );
    suggestClient.commit( suggesterCollection );
  }
  // check resp - if not OK, throw an Exception??
}
 
開發者ID:detnavillus,項目名稱:multifield_suggester_code,代碼行數:18,代碼來源:SuggestCollectionBuilder.java

示例6: examineFile

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
void examineFile(File file) throws FitsException, IOException, SolrServerException, XMLStreamException {
    System.out.println("Adding " + file.getName());
    FitsOutput fitsOutput = fits.examine(file);
    fitsOutput.addStandardCombinedFormat();

    SolrInputDocument solrDoc = new SolrInputDocument();

    this.indexFitsFileInfo(fitsOutput, solrDoc);
    this.indexFitsIdentities(fitsOutput, solrDoc);
    this.indexTechMetadata(fitsOutput, solrDoc);

    Document fitsXml = fitsOutput.getFitsXml();
    this.indexFitsXml(fitsXml, solrDoc);

    try {
        UpdateResponse response = solr.add(solrDoc);
        solr.commit();
    } catch (HttpSolrClient.RemoteSolrException e) {
        e.printStackTrace();
    }

}
 
開發者ID:little9,項目名稱:SolrFits,代碼行數:23,代碼來源:FitsExaminer.java

示例7: addItemsToIndex

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
@Override
    public void addItemsToIndex(SolrSimilarityConfigurationInt configuration) throws Exception {
        List<Item> items = solrItemDAO.getNonUserItems(configuration);
        // TODO: implement changeDate on items correctly! index from lastRun!!
        for (Item item : items) {
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", item.getTenantId() + item.getItemType() + item.getItemId());
            doc.addField("tenant_i", item.getTenantId());
            doc.addField("type_i", itemTypeDAO.getIdOfType(item.getTenantId(),item.getItemType()));
            doc.addField("id_i", idMappingDAO.lookupOnly(item.getItemId()));
            String all = "";
            Object parsedProfile = configuration.getConfiguration().jsonProvider().parse(item.getProfileData());
            for ( JsonPath jp : configuration.getIndexFields()) {
                all += addFieldToSolrString(jp, parsedProfile);
            }
            doc.addField("all", all);

            UpdateResponse response = solrClient.add(doc);
        }
        
//        logger.info("Response status:" + response.getStatus());
        
        solrClient.commit();
    }
 
開發者ID:major2015,項目名稱:easyrec_major,代碼行數:25,代碼來源:SolrSimilarityServiceImpl.java

示例8: write

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
private void write(final EmbeddedDocument child, final int level, final Document parent, final Document root)
		throws IOException {
	final SolrInputDocument inputDocument = prepareDocument(child, level, parent, root);
	final UpdateResponse response;

	// Free up memory.
	child.clearReader();

	// Null is a signal to skip.
	if (null == inputDocument) {
		return;
	}

	response = write(child, inputDocument);
	logger.info("Child document added to Solr in {}ms: \"{}\".", response.getElapsedTime(), child);

	for (EmbeddedDocument grandchild : child.getEmbeds()) {
		write(grandchild, level + 1, child, root);
	}
}
 
開發者ID:ICIJ,項目名稱:extract,代碼行數:21,代碼來源:SolrSpewer.java

示例9: addBeans

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
/**
 * Adds the beans supplied by the given iterator.
 * 
 * @param beanIterator
 *          the iterator which returns Beans
 * 
 * @return the response from the SolrServer
 */
public UpdateResponse addBeans(final Iterator<?> beanIterator)
    throws SolrServerException, IOException {
  UpdateRequest req = new UpdateRequest();
  req.setDocIterator(new Iterator<SolrInputDocument>() {
    
    @Override
    public boolean hasNext() {
      return beanIterator.hasNext();
    }
    
    @Override
    public SolrInputDocument next() {
      Object o = beanIterator.next();
      if (o == null) return null;
      return getBinder().toSolrInputDocument(o);
    }
    
    @Override
    public void remove() {
      beanIterator.remove();
    }
  });
  return req.process(this);
}
 
開發者ID:europeana,項目名稱:search,代碼行數:33,代碼來源:HttpSolrServer.java

示例10: runUpdate

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
protected UpdateResponse runUpdate(List<SolrInputDocument> batchToWrite) {
  try {
    UpdateResponse result = solr.add(batchToWrite);
    SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.BATCHES_WRITTEN.toString(), 1);      
    SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.DOCUMENTS_WRITTEN.toString(), batchToWrite.size());
    if (LOG.isDebugEnabled()) {
      SolrRecordWriter.incrementCounter(taskId, SolrCounters.class.getName(), SolrCounters.BATCH_WRITE_TIME.toString(), result.getElapsedTime());
    }
    return result;
  } catch (Throwable e) {
    if (e instanceof Exception) {
      setBatchWriteException((Exception) e);
    } else {
      setBatchWriteException(new Exception(e));
    }
    SolrRecordWriter.incrementCounter(taskId, getClass().getName() + ".errors", e.getClass().getName(), 1);
    LOG.error("Unable to process batch", e);
    return null;
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:21,代碼來源:BatchWriter.java

示例11: performUpdate

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
private void performUpdate(Delete obj) throws TranslatorException {
	Table table = obj.getTable().getMetadataObject();
	KeyRecord pk = table.getPrimaryKey();
	final String id = getRecordName(pk.getColumns().get(0));

	if (obj.getParameterValues() != null) {
		throw new TranslatorException(SolrPlugin.Event.TEIID20008, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20008));
	}
	
	SolrQueryExecution query = new SolrQueryExecution(ef, obj, this.executionContext, this.metadata, this.connection);
	query.execute();
	
	final UpdateRequest request = new UpdateRequest();
	query.walkDocuments(new SolrDocumentCallback() {
		@Override
		public void walk(SolrDocument doc) {
			SolrUpdateExecution.this.updateCount++;
			request.deleteById(doc.getFieldValue(id).toString());
		}
	});
	
	UpdateResponse response = this.connection.update(request);
	if (response.getStatus() != 0) {
		throw new TranslatorException(SolrPlugin.Event.TEIID20005, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20005, response.getStatus()));
	}		
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:27,代碼來源:SolrUpdateExecution.java

示例12: writeToIndex

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
/**
 * @param doc
 * @return Error message, if occurred; null otherwise.
 * @throws FatalIndexerException
 * @should write doc correctly
 */
public boolean writeToIndex(SolrInputDocument doc) throws FatalIndexerException {
    boolean success = false;
    int tries = RETRY_ATTEMPTS;

    while (!success && tries > 0) {
        tries--;
        try {
            UpdateResponse ur = server.add(doc);
            switch (ur.getStatus()) {
                case 0:
                    success = true;
                    break;
                default:
                    logger.error("Update status: {}", ur.getStatus());
            }
            return true;
        } catch (SolrServerException | IOException e) {
            logger.error(e.getMessage(), e);
        }
    }

    if (!success) {
        logger.error("Could not write document after {} attempts. Check the Solr server connection. Exiting...", RETRY_ATTEMPTS);
        rollback();
        throw new FatalIndexerException("Solr connection error");
    }

    return false;
}
 
開發者ID:intranda,項目名稱:goobi-viewer-indexer,代碼行數:36,代碼來源:SolrHelper.java

示例13: simpleWrite

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
/**
 * Write a document using the SolrTemplate
 */
@Test
@SuppressWarnings("unchecked")
public void simpleWrite() throws Exception {
    DiscoSolrDocument doc = discoDocument("1", "simpleWriteWithTemplate");

    // NOT TRUE WITH spring-data-solr 3: Don't need to use the saveBean(core, doc) method, because the document has the core as an annotation
    UpdateResponse res = solrTemplate.saveBean("discos", doc);
    assertNotNull(res);

    solrTemplate.commit("discos");
}
 
開發者ID:rmap-project,項目名稱:rmap,代碼行數:15,代碼來源:SimpleSolrIT.java

示例14: writeAndUpdateDiscoDocUsingPartialUpdate

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
@Test
public void writeAndUpdateDiscoDocUsingPartialUpdate() throws Exception {
    String solrCore = "discos";
    long expectedDocId = 200L;
    DiscoSolrDocument doc = new DiscoSolrDocument.Builder()
            .docId(String.valueOf(expectedDocId))
            .discoUri("http://doi.org/10.1109/disco/2")
            .discoStatus("ACTIVE")
            .build();

    UpdateResponse res = solrTemplate.saveBean(solrCore, doc);
    assertNotNull(res);
    assertEquals(0, res.getStatus());
    solrTemplate.commit(solrCore);


    assertEquals(doc, solrTemplate.getById(solrCore, expectedDocId, DiscoSolrDocument.class)
            .orElseThrow(() -> new RuntimeException(
                    "Expected to find a DiscoSolrDocument with ID " + doc.getDocId() + " in the index.")));

    // Update using Solr Atomic Updates (requires <updateLog/>)
    PartialUpdate update = new PartialUpdate(DiscoSolrDocument.DOC_ID, doc.getDocId());
    update.setValueOfField(DiscoSolrDocument.DISCO_STATUS, "INACTIVE");
    res = solrTemplate.saveBean(solrCore, update);
    assertNotNull(res);
    assertEquals(0, res.getStatus());
    solrTemplate.commit(solrCore);

    assertEquals("INACTIVE", solrTemplate.getById(solrCore, expectedDocId, DiscoSolrDocument.class)
            .orElseThrow(() -> new RuntimeException(
                    "Expected to find a DiscoSolrDocument with ID " + doc.getDocId() + " in the index."))
            .getDiscoStatus());
}
 
開發者ID:rmap-project,項目名稱:rmap,代碼行數:34,代碼來源:SimpleSolrIT.java

示例15: index

import org.apache.solr.client.solrj.response.UpdateResponse; //導入依賴的package包/類
@Override
public void index() throws IOException, SolrServerException {
    LOGGER.info("Sending optimize request to solr");
    UpdateResponse response = getSolrClient().optimize();
    LOGGER.info(MessageFormat.format("Optimize was {0}({1}ms)",
        (response.getStatus() == 0 ? "successful." : "UNSUCCESSFUL!"), response.getElapsedTime()));
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:8,代碼來源:MCRSolrOptimizeIndexHandler.java


注:本文中的org.apache.solr.client.solrj.response.UpdateResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。