Class EmbeddedSolrBackend

java.lang.Object
org.apache.solr.embedded.EmbeddedSolrBackend
All Implemented Interfaces:
AutoCloseable, SolrBackend

public class EmbeddedSolrBackend extends Object implements SolrBackend
SolrBackend backed by an in-process CoreContainer/EmbeddedSolrServer. No network or ZooKeeper overhead, although there's some request/response serialization.

Data is persisted in the given solrHome directory.

  • Constructor Details

    • EmbeddedSolrBackend

      public EmbeddedSolrBackend(Path solrHome)
    • EmbeddedSolrBackend

      public EmbeddedSolrBackend(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer solrServer)
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
    • EmbeddedSolrBackend

      public EmbeddedSolrBackend(org.apache.solr.core.CoreContainer container)
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
  • Method Details

    • getCoreContainer

      public org.apache.solr.core.CoreContainer getCoreContainer()
      Description copied from interface: SolrBackend
      Provides access to an embedded/in-process CoreContainer -- if available (else null). If there is more than one node, then one is returned.
      Specified by:
      getCoreContainer in interface SolrBackend
      Returns:
      can be null.
    • newSolrClient

      public org.apache.solr.client.solrj.SolrClient newSolrClient(String collection)
      Description copied from interface: SolrBackend
      Creates a new SolrClient defaulted to the given collection. The caller owns this client and is responsible for closing it. Callers that want a long-lived client should cache it themselves.
      Specified by:
      newSolrClient in interface SolrBackend
    • getSolrClient

      public org.apache.solr.client.solrj.embedded.EmbeddedSolrServer getSolrClient()
      Description copied from interface: SolrBackend
      Returns the node / admin (collection-less) SolrClient owned by this backend. The caller must NOT close it; it is released when this backend is SolrBackend.close()d. A CloudSolrClient should be returned if appropriate. While it *can* be used to target specific collections, please use SolrBackend.newSolrClient(String) for that instead.
      Specified by:
      getSolrClient in interface SolrBackend
    • createCollection

      public void createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create)
      Description copied from interface: SolrBackend
      Creates a collection (or core for single-node backends). Cloud backends honour numShards and replicationFactor; single-node backends (JettySolrRunner, EmbeddedSolrBackend) ignore those fields. Callers should use SolrBackend.hasCollection(String) first if they want to avoid errors when the collection already exists. Tests/benchmarks that want to test how this works should not use this to do so.
      Specified by:
      createCollection in interface SolrBackend
    • hasCollection

      public boolean hasCollection(String name)
      Description copied from interface: SolrBackend
      Checks if a collection or core with the given name exists.
      Specified by:
      hasCollection in interface SolrBackend
      Parameters:
      name - collection or core name to check
      Returns:
      true if the collection/core exists, false otherwise
    • reloadCollection

      public void reloadCollection(String name) throws org.apache.solr.common.SolrException
      Description copied from interface: SolrBackend
      Reloads a collection or core by this name. The purpose is typically to clear caches.
      Specified by:
      reloadCollection in interface SolrBackend
      Throws:
      org.apache.solr.common.SolrException
    • close

      public void close()
      Description copied from interface: SolrBackend
      Shuts down this backend, releases the admin client, and all other resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SolrBackend