Example usage for org.apache.solr.client.solrj SolrClient commit

List of usage examples for org.apache.solr.client.solrj SolrClient commit

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrClient commit.

Prototype

public UpdateResponse commit() throws SolrServerException, IOException 

Source Link

Document

Performs an explicit commit, causing pending documents to be committed for indexing waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access <p> Be very careful when triggering commits from the client side.

Usage

From source file:se.uu.ub.cora.solrindex.SolrRecordIndexer.java

License:Open Source License

private void tryToDeleteFromIndex(String type, String id) throws SolrServerException, IOException {
    SolrClient solrClient = solrClientProvider.getSolrClient();
    solrClient.deleteById(type + "_" + id);
    solrClient.commit();
}

From source file:uk.bl.wa.annotation.Annotator.java

License:Open Source License

private static void searchAndApplyAnnotations(Annotations ann, SurtPrefixSet oaSurts, String solrServer)
        throws SolrServerException, URISyntaxException, IOException {
    // Connect to solr:
    SolrClient solr = new HttpSolrClient(solrServer);

    // Set up annotator:
    Annotator anr = new Annotator(ann, oaSurts);

    // Loop over URL known to ACT:
    for (String scope : ann.getCollections().keySet()) {
        if ("resource".equals(scope)) {

            // Search for all matching URLs in SOLR:
            for (String uriKey : ann.getCollections().get(scope).keySet()) {
                LOG.info("Looking for URL: " + uriKey);
                SolrQuery parameters = new SolrQuery();
                parameters.set("q", "url:" + ClientUtils.escapeQueryChars(uriKey));
                searchAndApplyAnnotations(anr, solr, parameters);
            }/*from www.  ja  va2s  . c  o  m*/

        } else if ("root".equals(scope)) {

            // Search for all matching URLs in SOLR:
            for (String uriKey : ann.getCollections().get(scope).keySet()) {
                LOG.info("Looking for URLs starting with: " + uriKey);
                SolrQuery parameters = new SolrQuery();
                parameters.set("q", "url:" + ClientUtils.escapeQueryChars(uriKey) + "*");
                searchAndApplyAnnotations(anr, solr, parameters);
            }

        } else {
            LOG.warn("Ignoring annotations scoped as: " + scope);
        }
    }

    // And commit:
    solr.commit();

}