Example usage for org.apache.solr.core SolrCore close

List of usage examples for org.apache.solr.core SolrCore close

Introduction

In this page you can find the example usage for org.apache.solr.core SolrCore close.

Prototype

@Override
public void close() 

Source Link

Document

Close all resources allocated by the core if it is no longer in use...

Usage

From source file:at.newmedialab.lmf.search.services.cores.SolrCoreServiceImpl.java

License:Apache License

/**
 * Unregister the core with the name given as argument with the SOLR core admin.
 *
 * @param coreName/*from  ww  w  .j av  a 2s  .  c o m*/
 */
private void unregisterSolrCore(String coreName) {
    log.info("unregistering core {} from embedded SOLR service", coreName);
    SolrCore core = searchFilter.getCores().remove(coreName);
    if (core != null)
        core.close();
}

From source file:com.datasalt.pangool.solr.BatchWriter.java

License:Apache License

public synchronized void close(TaskAttemptContext context, SolrCore core)
        throws InterruptedException, SolrServerException, IOException {

    context.setStatus("Waiting for batches to complete");
    batchPool.shutdown();/*from  w w  w.  java 2 s  . c o m*/

    while (!batchPool.isTerminated()) {
        LOG.info(String.format("Waiting for %d items and %d threads to finish executing",
                batchPool.getQueue().size(), batchPool.getActiveCount()));
        batchPool.awaitTermination(5, TimeUnit.SECONDS);
    }
    context.setStatus("Optimizing Solr");
    solr.optimize(true, false, 1);
    context.setStatus("Closing Solr");
    core.close();
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java

License:Apache License

DirectoryReader newReaderInternal(Directory indexDir, IndexWriter writer, SolrCore core) throws IOException {
    DirectoryReader main = null;/*from w w w.j av a  2  s.  c  om*/
    if (writer != null) {
        main = standardFactory.newReader(writer, core);
    } else {
        main = standardFactory.newReader(indexDir, core);
    }
    if (!enabled) {
        LOG.info("Sidecar index not enabled");
        return main;
    }
    currentCore = core;
    CoreContainer container = core.getCoreDescriptor().getCoreContainer();
    SolrCore source = container.getCore(sourceCollection);
    if (source == null) {
        LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled.");
        try {
            return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main),
                    sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return main;
        }
    }
    if (source.isClosed()) {
        LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled.");
        try {
            return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main),
                    sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return main;
        }
    }
    DirectoryReader parallel = null;
    SolrIndexSearcher searcher = null;
    try {
        searcher = source.getNewestSearcher(true).get();
        parallel = buildParallelReader(main, searcher, true);
    } finally {
        if (searcher != null) {
            LOG.info("-- closing " + searcher);
            searcher.close();
        }
        source.close();
    }
    return parallel;
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java

License:Apache License

DirectoryReader reopen(DirectoryReader newMain, boolean rebuild) throws IOException {
    CoreContainer container = currentCore.getCoreDescriptor().getCoreContainer();
    SolrCore source = container.getCore(sourceCollection);
    if (source == null) {
        LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled.");
        try {//from   w ww. j  a  v a2s  .com
            return new SidecarIndexReader(this, newMain, null,
                    SidecarIndexReader.getSequentialSubReaders(newMain), sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return newMain;
        }
    }
    if (source.isClosed()) {
        LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled.");
        try {
            return new SidecarIndexReader(this, newMain, null,
                    SidecarIndexReader.getSequentialSubReaders(newMain), sourceCollection, null);
        } catch (Exception e1) {
            LOG.warn("Unexpected exception, returning single main index", e1);
            return newMain;
        }
    }
    DirectoryReader parallel = null;
    SolrIndexSearcher searcher = null;
    try {
        searcher = source.getNewestSearcher(true).get();
        parallel = buildParallelReader(newMain, searcher, rebuild);
    } finally {
        if (searcher != null && searcher.getIndexReader().getRefCount() > 0) {
            LOG.info("-- closing " + searcher);
            searcher.close();
        }
        if (source != null) {
            source.close();
        }
    }
    return parallel;
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactoryTest.java

License:Apache License

private void populate() throws Exception {
    // populate both indexes
    SolrCore source = cc.getCore("source");
    try {/* ww  w .ja  v a  2 s  .com*/
        for (int i = 99; i >= 0; i--) {
            AddUpdateCommand cmd = new AddUpdateCommand(makeReq(source));
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", "id" + i);
            doc.addField("side1_t", "foo bar side1 " + i);
            doc.addField("side2_t", "blah blah side2 " + i);
            cmd.solrDoc = doc;
            source.getUpdateHandler().addDoc(cmd);
        }
        source.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(source), false));
    } finally {
        source.close();
    }
    SolrCore target = cc.getCore("target");
    try {
        for (int i = 0; i < 101; i++) {
            AddUpdateCommand cmd = new AddUpdateCommand(makeReq(target));
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", "id" + i);
            doc.addField("text", "document " + i);
            cmd.solrDoc = doc;
            target.getUpdateHandler().addDoc(cmd);
            if (i == 99) {
                target.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(target), false));
            }
        }
        target.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(target), false));
    } finally {
        target.close();
    }
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactoryTest.java

License:Apache License

@Test
public void testBasics() throws Exception {
    System.err.println(cc.getAllCoreNames());
    populate();/*from   ww  w. j a  va 2 s  .co m*/
    SolrCore target = cc.getCore("target");
    SolrIndexSearcher searcher = target.getSearcher().get();
    Query q = new MatchAllDocsQuery();
    try {
        // verify the stored parts
        TopDocs td = searcher.search(q, 101);
        assertNotNull(td);
        for (ScoreDoc sd : td.scoreDocs) {
            Document doc = searcher.doc(sd.doc);
            String[] vals = doc.getValues("id");
            assertNotNull(vals);
            assertEquals(1, vals.length);
            String id = vals[0];
            vals = doc.getValues("text");
            assertNotNull(vals);
            assertEquals(1, vals.length);
            if (!id.equals("id100")) {
                // should have also the sidecar fields
                vals = doc.getValues("side1_t");
                assertNotNull(vals);
                assertEquals(1, vals.length);
                vals = doc.getValues("side2_t");
                assertNotNull(vals);
                assertEquals(1, vals.length);
            } else {
                // should not have the sidecar fields
                vals = doc.getValues("side1_t");
                assertTrue(vals == null || vals.length == 0);
                vals = doc.getValues("side2_t");
                assertTrue(vals == null || vals.length == 0);
            }
        }
        // verify the inverted parts
        q = new TermQuery(new Term("side1_t", "foo"));
        td = searcher.search(q, 101);
        assertEquals(100, td.totalHits);
        q = new TermQuery(new Term("side2_t", "blah"));
        td = searcher.search(q, 101);
        assertEquals(100, td.totalHits);
    } finally {
        searcher.close();
        target.close();
    }
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactoryTest.java

License:Apache License

@Test
public void testChanges() throws Exception {
    populate();//from  w  ww.j a  v a  2  s. c  om
    // add some docs, overwriting some of the existing ones
    SolrCore target = cc.getCore("target");
    try {
        for (int i = 50; i < 150; i++) {
            AddUpdateCommand cmd = new AddUpdateCommand(makeReq(target));
            cmd.overwrite = true;
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", "id" + i);
            doc.addField("text", "new document " + i);
            cmd.solrDoc = doc;
            target.getUpdateHandler().addDoc(cmd);
        }
        target.getUpdateHandler().commit(new CommitUpdateCommand(makeReq(target), false));
    } finally {
        target.close();
    }
    target = cc.getCore("target");
    SolrIndexSearcher searcher = target.getSearcher().get();
    Query q = new MatchAllDocsQuery();
    try {
        // verify the stored parts
        TopDocs td = searcher.search(q, 151);
        assertNotNull(td);
        for (ScoreDoc sd : td.scoreDocs) {
            Document doc = searcher.doc(sd.doc);
            System.err.println(doc);
        }
    } finally {
        searcher.close();
        target.close();
    }
}

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

License:Open Source License

@Override
public synchronized void close() {
    for (SolrCore core : cores.values())
        core.close();
    if (this.coreContainer != null)
        try {// w w w  . j av a  2 s.c o m
            this.coreContainer.shutdown();
            this.coreContainer = null;
        } catch (final Throwable e) {
            ConcurrentLog.logException(e);
        }
}

From source file:org.alfresco.solr.AlfrescoCoreAdminHandler.java

License:Open Source License

private boolean updateCore(SolrQueryRequest req, SolrQueryResponse rsp) {
    String coreName = null;/* w w w.  j a  v  a2  s . c o m*/
    SolrParams params = req.getParams();

    if (params.get("coreName") != null) {
        coreName = params.get("coreName");
    }

    if ((coreName == null) || (coreName.length() == 0)) {
        return false;
    }

    SolrCore core = null;
    try {
        core = coreContainer.getCore(coreName);

        if (core == null) {
            return false;
        }

        String configLocaltion = core.getResourceLoader().getConfigDir();
        File config = new File(configLocaltion, "solrcore.properties");
        updatePropertiesFile(params, config, null);

        coreContainer.reload(coreName);

        return true;
    } finally {
        //Decrement core open count
        if (core != null) {
            core.close();
        }
    }
}

From source file:org.gbif.ocurrence.index.solr.BatchWriter.java

License:Apache License

public synchronized void close(TaskAttemptContext context, SolrCore core)
        throws InterruptedException, SolrServerException, IOException {

    context.setStatus("Waiting for batches to complete");
    batchPool.shutdown();/*w  w  w. j ava  2 s .c o m*/

    while (!batchPool.isTerminated()) {
        LOG.info(String.format("Waiting for %d items and %d threads to finish executing",
                batchPool.getQueue().size(), batchPool.getActiveCount()));
        batchPool.awaitTermination(5, TimeUnit.SECONDS);
    }
    //reporter.setStatus("Committing Solr");
    //solr.commit(true, false);
    context.setStatus("Optimizing Solr");
    solr.optimize(true, false, 1);
    context.setStatus("Closing Solr");
    core.close();
}