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


Java UpdateRequest.deleteByQuery方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.request.UpdateRequest.deleteByQuery方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequest.deleteByQuery方法的具体用法?Java UpdateRequest.deleteByQuery怎么用?Java UpdateRequest.deleteByQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.request.UpdateRequest的用法示例。


在下文中一共展示了UpdateRequest.deleteByQuery方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteById

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
 * Deletes a list of documents by unique ID. Also removes any nested document of that ID.
 *
 * @param solrIDs
 *            the list of solr document IDs to delete
 */
public static UpdateResponse deleteById(String... solrIDs) {
    if (solrIDs == null || solrIDs.length == 0) {
        return null;
    }
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    UpdateResponse updateResponse = null;
    long start = System.currentTimeMillis();
    try {
        LOGGER.debug("Deleting \"{}\" from solr", Arrays.asList(solrIDs));
        UpdateRequest req = new UpdateRequest();
        //delete all documents rooted at this id
        if (MCRSolrUtils.useNestedDocuments()) {
            StringBuilder deleteQuery = new StringBuilder("_root_:(");
            for (String solrID : solrIDs) {
                deleteQuery.append('"');
                deleteQuery.append(MCRSolrUtils.escapeSearchValue(solrID));
                deleteQuery.append("\" ");
            }
            deleteQuery.setCharAt(deleteQuery.length() - 1, ')');
            req.deleteByQuery(deleteQuery.toString());
        }
        //for document without nested
        req.deleteById(Arrays.asList(solrIDs));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Delete request: {}", req.getXML());
        }
        updateResponse = req.process(solrClient);
        solrClient.commit();
    } catch (Exception e) {
        LOGGER.error("Error deleting document from solr", e);
    }
    long end = System.currentTimeMillis();
    MCRSolrIndexStatistic operations = MCRSolrIndexStatisticCollector.OPERATIONS;
    operations.addDocument(1);
    operations.addTime(end - start);
    return updateResponse;

}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:45,代码来源:MCRSolrIndexer.java

示例2: deleteDerivate

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
 * Convenient method to delete a derivate and all its files at once.
 *
 * @param id the derivate id
 * @return the solr response
 */
public static UpdateResponse deleteDerivate(String id) {
    if (id == null) {
        return null;
    }
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    UpdateResponse updateResponse = null;
    long start = System.currentTimeMillis();
    try {
        LOGGER.debug("Deleting derivate \"{}\" from solr", id);
        UpdateRequest req = new UpdateRequest();
        StringBuilder deleteQuery = new StringBuilder();
        deleteQuery.append("id:").append(id).append(" ");
        deleteQuery.append("derivateID:").append(id);
        if (MCRSolrUtils.useNestedDocuments()) {
            deleteQuery.append(" ").append("_root_:").append(id);
        }
        req.deleteByQuery(deleteQuery.toString());
        updateResponse = req.process(solrClient);
        solrClient.commit();
    } catch (Exception e) {
        LOGGER.error("Error deleting document from solr", e);
    }
    long end = System.currentTimeMillis();
    MCRSolrIndexStatistic operations = MCRSolrIndexStatisticCollector.OPERATIONS;
    operations.addDocument(1);
    operations.addTime(end - start);
    return updateResponse;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:35,代码来源:MCRSolrIndexer.java

示例3: deleteAllDocs

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
 * Entfernt alle Dokumente aus dem Solr-Index.
 */
public void deleteAllDocs() {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.setBasicAuthCredentials(USERNAME, PASSWORD);
    updateRequest.deleteByQuery("*:*");
    updateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
    try {
        updateRequest.process(solrClient);
        System.out.println("Alle Dokumente erfolgreich gelöscht!");
    } catch (SolrServerException|IOException e) {
        System.err.println("Fehler beim Löschen aller Dokumente: " + e.getMessage());
    }
}
 
开发者ID:saschaszott,项目名称:suma-tech,代码行数:16,代码来源:SolrIndexer.java

示例4: clearCollection

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/** Clear given collection. */
static void clearCollection(String collection, AuthorizedSolrClient client) throws IOException {
  try {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.setAction(UpdateRequest.ACTION.COMMIT, true, true);
    updateRequest.deleteByQuery("*:*");
    client.process(collection, updateRequest);
  } catch (SolrServerException e) {
    throw new IOException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:SolrIOTestUtils.java

示例5: delQ

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
protected UpdateResponse delQ(SolrServer server, SolrParams params, String... queries) throws IOException, SolrServerException {
  UpdateRequest ureq = new UpdateRequest();
  ureq.setParams(new ModifiableSolrParams(params));
  for (String q: queries) {
    ureq.deleteByQuery(q);
  }
  return ureq.process(server);
}
 
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:BaseDistributedSearchTestCase.java

示例6: distribDelete

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
public void distribDelete(DeleteUpdateCommand cmd, List<Node> nodes, ModifiableSolrParams params, boolean sync) throws IOException {
  
  for (Node node : nodes) {
    UpdateRequest uReq = new UpdateRequest();
    uReq.setParams(params);
    if (cmd.isDeleteById()) {
      uReq.deleteById(cmd.getId(), cmd.getVersion());
    } else {
      uReq.deleteByQuery(cmd.query);
    }
    
    submit(new Req(cmd.toString(), node, uReq, sync), false);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:SolrCmdDistributor.java

示例7: distribDelete

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
public void distribDelete(DeleteUpdateCommand cmd, List<Node> nodes, ModifiableSolrParams params, boolean sync) throws IOException {
  
  for (Node node : nodes) {
    UpdateRequest uReq = new UpdateRequest();
    uReq.setParams(params);
    if (cmd.isDeleteById()) {
      uReq.deleteById(cmd.getId(), cmd.getVersion());
    } else {
      uReq.deleteByQuery(cmd.query);
    }
    
    submit(new Req(cmd.toString(), node, uReq, sync));
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:15,代码来源:SolrCmdDistributor.java

示例8: setupCores

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
private UpdateRequest setupCores() throws SolrServerException, IOException {
  UpdateRequest up = new UpdateRequest();
  up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
  up.deleteByQuery("*:*");
  up.process(getSolrCore0());
  up.process(getSolrCore1());
  up.clear();

  // Add something to each core
  SolrInputDocument doc = new SolrInputDocument();
  doc.setField("id", "AAA");
  doc.setField("name", "core0");

  // Add to core0
  up.add(doc);
  up.process(getSolrCore0());

  // Add to core1
  doc.setField("id", "BBB");
  doc.setField("name", "core1");
  up.add(doc);
  up.process(getSolrCore1());

  // Now Make sure AAA is in 0 and BBB in 1
  SolrQuery q = new SolrQuery();
  QueryRequest r = new QueryRequest(q);
  q.setQuery("id:AAA");
  assertEquals(1, r.process(getSolrCore0()).getResults().size());
  assertEquals(0, r.process(getSolrCore1()).getResults().size());

  assertEquals(1,
      getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
  assertEquals(0,
      getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());

  assertEquals(0,
      getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
  assertEquals(1,
      getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());

  return up;
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:MergeIndexesExampleTestBase.java

示例9: doDBQ

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
void doDBQ(String q, String... reqParams) throws Exception {
  UpdateRequest req = new UpdateRequest();
  req.deleteByQuery(q);
  req.setParams(params(reqParams));
  req.process(cloudClient);
}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:TestDistribDocBasedVersion.java

示例10: deleteByQuery

import org.apache.solr.client.solrj.request.UpdateRequest; //导入方法依赖的package包/类
/**
 * Deletes documents from the index based on a query, specifying max time before commit
 * @param query  the query expressing what documents to delete
 * @param commitWithinMs  max time (in ms) before a commit will happen 
 * @throws IOException If there is a low-level I/O error.
 * @since 3.6
 */
public UpdateResponse deleteByQuery(String query, int commitWithinMs) throws SolrServerException, IOException {
  UpdateRequest req = new UpdateRequest();
  req.deleteByQuery(query);
  req.setCommitWithin(commitWithinMs);
  return req.process(this);
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:SolrServer.java


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