Java Code Examples for org.apache.solr.client.solrj.response.UpdateResponse#getElapsedTime()

The following examples show how to use org.apache.solr.client.solrj.response.UpdateResponse#getElapsedTime() . 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: SolrController.java    From Spring-Boot-Book with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/delById/{id}")
public String delById(@PathVariable("id") String id) throws IOException, SolrServerException {
    //根据id删除信息
    UpdateResponse updateResponse = solrClient.deleteById(id);
    //执行的时间
    long elapsedTime = updateResponse.getElapsedTime();

    int qTime = updateResponse.getQTime();
    //请求地址
    String requestUrl = updateResponse.getRequestUrl();
    //请求的结果{responseHeader={status=0,QTime=2}}
    NamedList<Object> response = updateResponse.getResponse();
    //请求结果的头{status=0,QTime=2}
    NamedList responseHeader = updateResponse.getResponseHeader();
    //请求的状态 0
    solrClient.commit();
    int status = updateResponse.getStatus();
    //成功则返回0.要是没有文档被删除也会返回0,代表根本没有
    return status == 0 ? "success" : "failed";
}
 
Example 2
Source File: SolrControllerTest.java    From Spring-Boot-Book with Apache License 2.0 6 votes vote down vote up
@Test
public void delById()  throws IOException, SolrServerException {
    //根据id删除信息
    UpdateResponse updateResponse = solrClient.deleteById("8888888");
    //执行的时间
    long elapsedTime = updateResponse.getElapsedTime();
    int qTime = updateResponse.getQTime();
    //请求地址
    String requestUrl = updateResponse.getRequestUrl();
    //请求的结果{responseHeader={status=0,QTime=2}}
    NamedList<Object> response = updateResponse.getResponse();
    //请求结果的头{status=0,QTime=2}
    NamedList responseHeader = updateResponse.getResponseHeader();
    //请求的状态 0
    solrClient.commit();
    int status = updateResponse.getStatus();
    //成功则返回0.要是没有文档被删除也会返回0,代表根本没有

}
 
Example 3
Source File: SolrSearchServer.java    From vind with Apache License 2.0 6 votes vote down vote up
@Override
public DeleteResult deleteWithin(Document doc, int withinMs) {
    try {
        long qTime = 0;
        long elapsedTime = 0;
        solrClientLogger.debug(">>> delete({})", doc.getId());
        final UpdateResponse deleteResponse = withinMs < 0 ? solrClient.deleteById(doc.getId()) : solrClient.deleteById(doc.getId(), withinMs);
        qTime = deleteResponse.getQTime();
        elapsedTime = deleteResponse.getElapsedTime();
        //Deleting nested documents
        final UpdateResponse deleteNestedResponse = withinMs < 0 ? solrClient.deleteByQuery("_root_:" + doc.getId()) : solrClient.deleteByQuery("_root_:" + doc.getId(), withinMs);
        qTime += deleteNestedResponse.getQTime();
        elapsedTime += deleteNestedResponse.getElapsedTime();

        return new DeleteResult(qTime).setElapsedTime(elapsedTime);
    } catch (SolrServerException | IOException e) {
        log.error("Cannot delete document {}", doc.getId() , e);
        throw new SearchServerException("Cannot delete document", e);
    }
}
 
Example 4
Source File: SolrSearchServer.java    From vind with Apache License 2.0 6 votes vote down vote up
@Override
public DeleteResult execute(Delete delete, DocumentFactory factory) {
    String query = SolrUtils.Query.buildFilterString(delete.getQuery(), factory, delete.getUpdateContext(),true);
    try {
        solrClientLogger.debug(">>> delete query({})", query);

        final UpdateResponse deleteChildrenResponse =
                solrClient.deleteByQuery(
                        String.format("{!child of='_type_:%s' v='%s'}",
                                factory.getType(),
                                query.trim().replaceAll("'","\"")));
        long qTime = deleteChildrenResponse.getQTime();
        long elapsedTime = deleteChildrenResponse.getElapsedTime();
        final UpdateResponse deleteResponse = solrClient.deleteByQuery(query.trim().replaceAll("^\\+",""));
        qTime += deleteResponse.getQTime();
        elapsedTime += deleteResponse.getElapsedTime();

        return new DeleteResult(qTime).setElapsedTime(elapsedTime);
    } catch (SolrServerException | IOException e) {
        log.error("Cannot delete with query {}", query, e);
        throw new SearchServerException("Cannot delete with query", e);
    }
}