List of usage examples for org.apache.solr.client.solrj.request UpdateRequest setCommitWithin
public AbstractUpdateRequest setCommitWithin(int commitWithin)
From source file:at.newmedialab.lmf.search.services.indexing.SolrCoreRuntime.java
License:Apache License
/** * Queue the input document in the document queue of this SolrCoreRuntime and check whether it is * necessary to commit.//from w w w .j a v a2s.co m * * @param doc the document to be added to the Solr Core */ public void queueInputDocument(SolrInputDocument doc) { if (doc != null) { serverLock.lock(); try { final Object fv = doc.getFieldValue("id"); if (fv != null) { UpdateRequest update = new UpdateRequest(); update.setCommitWithin(10000); update.add(doc); //update.setAction(ACTION.COMMIT, false, false); server.request(update); } else { log.warn("({}) rejected document without 'id' for update", config.getName()); } } catch (IOException e) { log.warn("I/O exception while adding SOLR document to index", e); } catch (SolrServerException e) { log.warn("server exception while adding SOLR document to index", e); } finally { serverLock.unlock(); } } }
From source file:at.newmedialab.lmf.search.services.indexing.SolrCoreRuntime.java
License:Apache License
/** * Queue the deletion of a document in the Solr Core and check whether it is necessary to * commit.// w w w. j a v a 2 s. c o m * * @param docId */ public void queueDeletion(String docId) { serverLock.lock(); try { UpdateRequest update = new UpdateRequest(); update.setCommitWithin(10000); update.deleteById(docId); //update.setAction(ACTION.COMMIT, false, false); server.request(update); } catch (IOException e) { log.warn("I/O exception while removing SOLR document from index", e); } catch (SolrServerException e) { log.warn("server exception while removing SOLR document from index", e); } finally { serverLock.unlock(); } }
From source file:com.digitalpebble.storm.crawler.solr.SolrConnection.java
License:Apache License
public static UpdateRequest getRequest(Map stormConf, String boltType) { int commitWithin = ConfUtils.getInt(stormConf, "solr." + boltType + ".commit.within", -1); UpdateRequest request = new UpdateRequest(); if (commitWithin != -1) { request.setCommitWithin(commitWithin); }/*w ww.j a v a 2 s . c o m*/ return request; }
From source file:edu.harvard.gis.hhypermap.bop.SolrUpdateSlammer.java
License:Apache License
private void sendDoc(SolrInputDocument doc) throws IOException, SolrServerException { UpdateRequest req = new UpdateRequest(); req.add(doc);/*from w w w .j a v a2s.co m*/ req.setParams(updateParams); req.setCommitWithin(1000); req.process(client, collection); }
From source file:org.kitesdk.morphline.solr.SolrServerDocumentLoader.java
License:Apache License
private void sendDeletes(List deletes) throws SolrServerException, IOException { if (deletes.size() > 0) { UpdateRequest req = new UpdateRequest(); for (Object delete : deletes) { if (delete instanceof String) { req.deleteById((String) delete); // add the delete to the req list } else { String query = ((QueryStringHolder) delete).getQuery(); req.deleteByQuery(query); // add the delete to the req list }//from w w w .j ava2 s . com } req.setCommitWithin(-1); log(req.process(server)); deletes.clear(); } }
From source file:org.teiid.resource.adapter.solr.SolrConnectionImpl.java
License:Open Source License
@Override public UpdateResponse update(UpdateRequest request) throws TranslatorException { try {/* w w w . ja v a 2s. com*/ request.setCommitWithin(-1); request.setAction(UpdateRequest.ACTION.COMMIT, false, false); return request.process(this.server); } catch (SolrServerException e) { throw new TranslatorException(e); } catch (IOException e) { throw new TranslatorException(e); } }
From source file:org.topicquests.solr.Solr3Client.java
License:Apache License
private IResult addUpdateData(Map<String, Object> fields) { IResult result = new ResultPojo(); if (fields.isEmpty()) { //result.addErrorString("SolrClient got an empty document"); return result; }/*from w ww . j a v a 2s . c o m*/ log.logDebug("Solr3Client.addUpdateData-1 " + fields.size()); int status = 0; try { SolrInputDocument document = mapToDocument(fields); //updateMapToDocument(fields); log.logDebug("Solr3Client.addUpdateData-2 " + document); UpdateRequest ur = new UpdateRequest(); ur.add(document); ur.setCommitWithin(1000); UpdateResponse response = ur.process(updateServer); status = response.getStatus(); //TODO full commit or soft commit? //server.commit(); } catch (Exception e) { result.addErrorString(e.getMessage()); log.logError("Solr3Client.addUpdateData error-1 " + e.getMessage() + " " + fields, e); } result.setResultObject(new Integer(status)); return result; }
From source file:org.topicquests.solr.SolrCloudClient.java
License:Apache License
IResult addUpdateData(Map<String, Object> fields) {
IResult result = new ResultPojo();
if (fields.isEmpty()) {
//result.addErrorString("SolrClient got an empty document");
return result;
}/*from www .j av a 2 s . com*/
log.logDebug("SolrCloudClient.addUpdateData-1 " + fields.size());
int status = 0;
try {
SolrInputDocument document = mapToDocument(fields);
log.logDebug("SolrCloudClient.addUpdateData-2 " + document);
UpdateRequest ur = new UpdateRequest();
ur.add(document);
ur.setCommitWithin(2000);
UpdateResponse response = ur.process(updateServer);
status = response.getStatus();
//commitWithin means the commit will happen regardless
if (shouldCommit)
updateServer.commit();
} catch (Exception e) {
result.addErrorString(e.getMessage());
log.logError("SolrCloudClient.addUpdateData error-1 " + e.getMessage() + " " + fields, e);
}
result.setResultObject(new Integer(status));
return result;
}
From source file:ru.org.linux.search.SearchQueueListener.java
License:Apache License
public void handleMessage(UpdateComments msgUpdate) throws MessageNotFoundException, IOException, SolrServerException { logger.info("Indexing comments " + msgUpdate.getMsgids()); UpdateRequest rq = new UpdateRequest(); rq.setCommitWithin(10000); boolean delete = false; for (Integer msgid : msgUpdate.getMsgids()) { if (msgid == 0) { logger.warn("Skipping MSGID=0!!!"); continue; }//from www . j a v a 2s . c om Comment comment = commentService.getById(msgid); if (comment.isDeleted()) { logger.info("Deleting comment " + comment.getId() + " from solr"); solrServer.deleteById(Integer.toString(comment.getId())); delete = true; } else { // ? ?? ? // ? ?? - , .. ? // Topic topic = topicDao.getById(comment.getTopicId()); String message = msgbaseDao.getMessageText(comment.getId()).getText(); rq.add(processComment(topic, comment, message)); } } if (rq.getDocuments() != null && !rq.getDocuments().isEmpty()) { rq.process(solrServer); } if (delete) { solrServer.commit(); } }