本文整理汇总了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;
}
示例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;
}
示例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());
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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;
}
示例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);
}
示例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);
}