Class SolrCollectionInitializer

java.lang.Object
edu.byu.hbll.solr.SolrCollectionInitializer

public class SolrCollectionInitializer extends Object
Creates or reloads a SolrCloud collection based on the provided configset, or an existing configset if one is not provided.

Example:


 new SolrCollectionInitializer()
     .zkHosts(Arrays.asList("zk1.example.com","zk2.example.com","zk3.example.com"))
     .chroot("/solr")
     .collectionName("search")
     .configsetName("search")
     .configsetPath(Paths.get("configsets/search/conf"))
     .shardCount(1)
     .replicaCount(2)
     .initialize();
 
Author:
bwelker
  • Field Details

    • DEFAULT_ZK_HOSTS

      public static final List<String> DEFAULT_ZK_HOSTS
      Default Zookeeper host list: ["localhost"].
    • DEFAULT_CHROOT

      public static final String DEFAULT_CHROOT
      Default Zookeeper chroot path: "/solr".
      See Also:
    • DEFAULT_SHARD_COUNT

      public static final int DEFAULT_SHARD_COUNT
      Default shard count: 1.
      See Also:
    • DEFAULT_REPLICA_COUNT

      public static final int DEFAULT_REPLICA_COUNT
      Default replica count: 1.
      See Also:
  • Constructor Details

    • SolrCollectionInitializer

      public SolrCollectionInitializer()
  • Method Details

    • zkHosts

      public SolrCollectionInitializer zkHosts(List<String> zkHosts)
      Sets the zookeeper hosts for this initializer.
      Parameters:
      zkHosts - the zookeeper hosts.
      Returns:
      SolrCollectionInitializer
    • chroot

      public SolrCollectionInitializer chroot(String chroot)
      Sets the zookeeper chroot for this initializer.
      Parameters:
      chroot - the zookeeper chroot.
      Returns:
      SolrCollectionInitializer
    • baseUris

      public SolrCollectionInitializer baseUris(List<String> baseUris)
      Sets the solr base uris. If set, zkHosts and chroot are ignored.

      Note: The recommended practice is to specify solr base uris rather than interface directly with zookeeper. https://solr.apache.org/guide/solr/latest/upgrade-notes/major-changes-in-solr-9.html#solrj

      Parameters:
      baseUris - the solr base uris.
      Returns:
      SolrCollectionInitializer
    • collectionName

      public SolrCollectionInitializer collectionName(String collectionName)
      Sets the collection name for this initializer.
      Parameters:
      collectionName - the collection name.
      Returns:
      SolrCollectionInitializer
    • configsetName

      public SolrCollectionInitializer configsetName(String configsetName)
      Sets the configset name for this initializer.
      Parameters:
      configsetName - the name of the configset.
      Returns:
      SolrCollectionInitializer
    • configsetPath

      public SolrCollectionInitializer configsetPath(Path configsetPath)
      Sets the location of the configset for this initializer.
      Parameters:
      configsetPath - the location of the configset.
      Returns:
      SolrCollectionInitializer
    • configsetResourceName

      public SolrCollectionInitializer configsetResourceName(String configsetResourceName)
      Sets the name of the classpath resource containing the configset.
      Parameters:
      configsetResourceName - the name of the classpath resource containing the configset.
      Returns:
      SolrCollectionInitializer
    • shardCount

      public SolrCollectionInitializer shardCount(int shardCount)
      Sets the shard count for this initializer.
      Parameters:
      shardCount - the shard count for the collection.
      Returns:
      SolrCollectionInitializer
    • replicaCount

      public SolrCollectionInitializer replicaCount(int replicaCount)
      Sets the replica count for this initializer.
      Parameters:
      replicaCount - the replica count for the collection.
      Returns:
      SolrCollectionInitializer
    • createCloudClient

      public org.apache.solr.client.solrj.impl.CloudSolrClient createCloudClient()
      Creates a CloudSolrClient based on the parameters set including the default collection.
      Returns:
      a new Solr client
    • createHttpClient

      public org.apache.solr.client.solrj.SolrClient createHttpClient()
      Creates a Solr client based on an LBHttp2SolrClient and the parameters set including the default collection.
      Returns:
      a new Solr client
    • initializeHttp

      public org.apache.solr.client.solrj.SolrClient initializeHttp() throws IOException, org.apache.solr.client.solrj.SolrServerException
      Uploads the solr config (if one is provided), and initializes or reloads the solr collection with the config. This is done using the LBHttp2SolrClient.
      Returns:
      a solr client for this collection
      Throws:
      IOException - If an IO error occurs.
      org.apache.solr.client.solrj.SolrServerException - If a Solr error occurs.
    • initialize

      public org.apache.solr.client.solrj.impl.CloudSolrClient initialize() throws IOException, org.apache.solr.client.solrj.SolrServerException
      Uploads the solr config (if one is provided), and initializes or reloads the solr collection with the config. This is done using the CloudSolrClient.
      Returns:
      a solr client for this collection
      Throws:
      IOException - If an IO error occurs.
      org.apache.solr.client.solrj.SolrServerException - If a Solr error occurs.