Java Code Examples for org.apache.solr.update.DeleteUpdateCommand#setQuery()

The following examples show how to use org.apache.solr.update.DeleteUpdateCommand#setQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void deleteByQuery(String query) throws IOException
{
    UpdateRequestProcessor processor = null;
    try (SolrQueryRequest request = newSolrQueryRequest())
    {
        processor = this.core.getUpdateProcessingChain(null).createProcessor(request, newSolrQueryResponse());
        DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
        delDocCmd.setQuery(query);
        processor.processDelete(delDocCmd);
    }
    finally
    {
        if (processor != null)
        {
            processor.finish();
        }
    }
}
 
Example 2
Source File: SolrInformationServer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void deleteNode(UpdateRequestProcessor processor, SolrQueryRequest request, long dbid) throws IOException
{
    if (getDocListSize(FIELD_DBID + ":" + dbid) > 0)
    {
        DeleteUpdateCommand delDocCmd = new DeleteUpdateCommand(request);
        delDocCmd.setQuery(FIELD_DBID + ":" + dbid);
        processor.processDelete(delDocCmd);
    }
}
 
Example 3
Source File: SolrUpdateService.java    From chronix.server with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes documents identified by the given documents.
 *
 * @param docs the documents
 * @throws IOException iff something goes wrong
 */
public void delete(Collection<Document> docs) throws IOException {
    DeleteUpdateCommand cmd = new DeleteUpdateCommand(req);
    cmd.commitWithin = COMMIT_WITHIN;
    cmd.setFlags(DeleteUpdateCommand.BUFFERING);
    cmd.setQuery("{!terms f=" + ID + "}" + docs.stream().map(it -> it.get(ID)).collect(joining(",")));
    updateProcessor.processDelete(cmd);
}
 
Example 4
Source File: UpdateIndexAuthorizationProcessorTest.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private void verifyAuthorized(String collection, String user) throws Exception {
  SolrQueryRequestBase req = new SolrQueryRequestBase(core, new MapSolrParams(new HashMap())) {};
  getProcessor(collection, user).processAdd(new AddUpdateCommand(req));
  getProcessor(collection, user).processDelete(new DeleteUpdateCommand(req));
  DeleteUpdateCommand deleteByQueryCommand = new DeleteUpdateCommand(req);
  deleteByQueryCommand.setQuery("*:*");
  getProcessor(collection, user).processDelete(deleteByQueryCommand);
  getProcessor(collection, user).processMergeIndexes(new MergeIndexesCommand(null, req));
  getProcessor(collection, user).processCommit(new CommitUpdateCommand(req, false));
  getProcessor(collection, user).processRollback(new RollbackUpdateCommand(req));
  getProcessor(collection, user).finish();
}
 
Example 5
Source File: DocExpirationUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void run() {
  // setup the request context early so the logging (including any from 
  // shouldWeDoPeriodicDelete() ) includes the core context info
  final LocalSolrQueryRequest req = new LocalSolrQueryRequest
    (factory.core, Collections.<String,String[]>emptyMap());
  try {
    // HACK: to indicate to PKI that this is a server initiated request for the purposes
    // of distributed requet/credential forwarding...
    req.setUserPrincipalName(PKIAuthenticationPlugin.NODE_IS_USER);
    
    final SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap<>(1));
    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
    try {
      
      if (! factory.iAmInChargeOfPeriodicDeletes() ) {
        // No-Op
        return;
      }
      log.info("Beginning periodic deletion of expired docs");

      UpdateRequestProcessorChain chain = core.getUpdateProcessingChain(deleteChainName);
      UpdateRequestProcessor proc = chain.createProcessor(req, rsp);
      if (null == proc) {
        log.warn("No active processors, skipping automatic deletion of expired docs using chain: {}"
                 , deleteChainName);
        return;
      }
      try {
        DeleteUpdateCommand del = new DeleteUpdateCommand(req);
        del.setQuery("{!cache=false}" + expireField + ":[* TO " +
            SolrRequestInfo.getRequestInfo().getNOW().toInstant()
                     + "]");
        proc.processDelete(del);
        
        // TODO: should this be more configurable? 
        // TODO: in particular: should hard commit be optional?
        CommitUpdateCommand commit = new CommitUpdateCommand(req, false);
        commit.softCommit = true;
        commit.openSearcher = true;
        proc.processCommit(commit);
        
      } finally {
        try {
          proc.finish();
        } finally {
          proc.close();
        }
      }

      log.info("Finished periodic deletion of expired docs");
    } catch (IOException ioe) {
      log.error("IOException in periodic deletion of expired docs: {}",
                ioe.getMessage(), ioe);
      // DO NOT RETHROW: ScheduledExecutor will suppress subsequent executions
    } catch (RuntimeException re) {
      log.error("Runtime error in periodic deletion of expired docs: {}",
                re.getMessage(), re);
      // DO NOT RETHROW: ScheduledExecutor will suppress subsequent executions
    } finally {
      SolrRequestInfo.clearRequestInfo();
    }
  } finally {
    req.close();
  }
}
 
Example 6
Source File: ChronixRetentionHandler.java    From chronix.server with Apache License 2.0 2 votes vote down vote up
/**
 * Triggers the deletion
 *
 * @param processor the update processor do process deletions
 * @param req       the solr query request information
 * @throws IOException if bad things happen
 */
private void deleteOldDocuments(String deletionQuery, UpdateRequestProcessor processor, SolrQueryRequest req) throws IOException {
    DeleteUpdateCommand delete = new DeleteUpdateCommand(req);
    delete.setQuery(deletionQuery);
    processor.processDelete(delete);
}