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(boolean waitFlush, boolean waitSearcher, boolean softCommit)
        throws SolrServerException, IOException 

Source Link

Document

Performs an explicit commit, causing pending documents to be committed for indexing Be very careful when triggering commits from the client side.

Usage

From source file:com.frank.search.solr.core.SolrTemplate.java

License:Apache License

@Override
public void softCommit() {
    if (VersionUtil.isSolr3XAvailable()) {
        throw new UnsupportedOperationException(
                "Soft commit is not available for solr version lower than 4.x - Please check your depdendencies.");
    }/*from   ww  w . j  a va  2s  . c o m*/
    execute(new SolrCallback<UpdateResponse>() {
        @Override
        public UpdateResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
            return solrClient.commit(true, true, true);
        }
    });
}

From source file:net.hasor.search.server.rsf.service.SorlDumpService.java

License:Apache License

private UpdateSearchResult doExecute(ExecuteService exec) {
    try {// w w  w. j  a v  a 2 s. c  o  m
        SolrClient solrClient = this.getSolrClient();
        RsfOptionSet optionSet = this.getRsfOptionSet();
        String commit = optionSet.getOption(OptionConstant.COMMIT_KEY);
        //
        UpdateResponse res = exec.doExecute(solrClient);
        if (StringUtils.equalsBlankIgnoreCase(commit, OptionConstant.COMMIT_VALUE)) {
            boolean waitFlush = StrUtils.parseBool(optionSet.getOption(OptionConstant.WAIT_FLUSH_KEY), true);
            boolean waitSearcher = StrUtils.parseBool(optionSet.getOption(OptionConstant.WAIT_SEARCHER_KEY),
                    true);
            boolean softCommit = StrUtils.parseBool(optionSet.getOption(OptionConstant.SOFT_COMMIT_KEY), false);
            res = solrClient.commit(waitFlush, waitSearcher, softCommit);
        }
        //
        UpdateSearchResult result = new UpdateSearchResult();
        result.setSuccess(false);
        result.setElapsedTime(res.getElapsedTime());
        result.setStatus(res.getStatus());
        result.setQueryTime(res.getQTime());
        return result;
    } catch (Throwable e) {
        UpdateSearchResult result = new UpdateSearchResult();
        result.setSuccess(false);
        result.setThrowable(new SearchException(e.getMessage()));
        LoggerHelper.logSevere(e.getMessage(), e);
        return result;
    }
}

From source file:net.yacy.cora.federate.solr.instance.ServerShard.java

License:Open Source License

/**
 * Performs an explicit commit, causing pending documents to be committed for indexing
 * @param waitFlush  block until index changes are flushed to disk
 * @param waitSearcher  block until a new searcher is opened and registered as the main query searcher, making the changes visible
 * @param softCommit makes index changes visible while neither fsync-ing index files nor writing a new index descriptor
 * @throws IOException If there is a low-level I/O error.
 *///w w  w.  ja v  a 2s  .com
@Override
public UpdateResponse commit(boolean waitFlush, boolean waitSearcher, boolean softCommit)
        throws SolrServerException, IOException {
    if (!this.writeEnabled)
        return _dummyOKResponse;
    UpdateResponse ur = null;
    for (SolrClient s : this.shards)
        ur = s.commit(waitFlush, waitSearcher, softCommit);
    return ur;
}

From source file:org.broadleafcommerce.core.search.service.solr.index.SolrIndexServiceImpl.java

License:Open Source License

@Override
public void commit(SolrClient server, boolean softCommit, boolean waitSearcher, boolean waitFlush)
        throws ServiceException, IOException {
    try {// ww w.j  a  v a2 s.  c om
        if (!this.commit) {
            LOG.warn(
                    "The flag / property \"solr.index.commit\" is set to false but a commit is being forced via the API.");
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Committing changes to Solr index: softCommit: " + softCommit + ", waitSearcher: "
                    + waitSearcher + ", waitFlush: " + waitFlush);
        }

        server.commit(waitFlush, waitSearcher, softCommit);
    } catch (SolrServerException e) {
        throw new ServiceException("Could not commit changes to Solr index", e);
    }
}