Package edu.byu.hbll.solr
Class SolrCollectionInitializer
java.lang.Object
edu.byu.hbll.solr.SolrCollectionInitializer
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault Zookeeper chroot path: "/solr".static final intDefault replica count: 1.static final intDefault shard count: 1.Default Zookeeper host list: ["localhost"]. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the solr base uris.Sets the zookeeper chroot for this initializer.collectionName(String collectionName) Sets the collection name for this initializer.configsetName(String configsetName) Sets the configset name for this initializer.configsetPath(Path configsetPath) Sets the location of the configset for this initializer.configsetResourceName(String configsetResourceName) Sets the name of the classpath resource containing the configset.org.apache.solr.client.solrj.impl.CloudSolrClientCreates aCloudSolrClientbased on the parameters set including the default collection.org.apache.solr.client.solrj.SolrClientCreates a Solr client based on anLBHttp2SolrClientand the parameters set including the default collection.org.apache.solr.client.solrj.impl.CloudSolrClientUploads the solr config (if one is provided), and initializes or reloads the solr collection with the config.org.apache.solr.client.solrj.SolrClientUploads the solr config (if one is provided), and initializes or reloads the solr collection with the config.replicaCount(int replicaCount) Sets the replica count for this initializer.shardCount(int shardCount) Sets the shard count for this initializer.Sets the zookeeper hosts for this initializer.
-
Field Details
-
DEFAULT_ZK_HOSTS
Default Zookeeper host list: ["localhost"]. -
DEFAULT_CHROOT
Default Zookeeper chroot path: "/solr".- See Also:
-
DEFAULT_SHARD_COUNT
public static final int DEFAULT_SHARD_COUNTDefault shard count: 1.- See Also:
-
DEFAULT_REPLICA_COUNT
public static final int DEFAULT_REPLICA_COUNTDefault replica count: 1.- See Also:
-
-
Constructor Details
-
SolrCollectionInitializer
public SolrCollectionInitializer()
-
-
Method Details
-
zkHosts
Sets the zookeeper hosts for this initializer.- Parameters:
zkHosts- the zookeeper hosts.- Returns:
- SolrCollectionInitializer
-
chroot
Sets the zookeeper chroot for this initializer.- Parameters:
chroot- the zookeeper chroot.- Returns:
- SolrCollectionInitializer
-
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
Sets the collection name for this initializer.- Parameters:
collectionName- the collection name.- Returns:
- SolrCollectionInitializer
-
configsetName
Sets the configset name for this initializer.- Parameters:
configsetName- the name of the configset.- Returns:
- SolrCollectionInitializer
-
configsetPath
Sets the location of the configset for this initializer.- Parameters:
configsetPath- the location of the configset.- Returns:
- SolrCollectionInitializer
-
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
Sets the shard count for this initializer.- Parameters:
shardCount- the shard count for the collection.- Returns:
- SolrCollectionInitializer
-
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 aCloudSolrClientbased 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 anLBHttp2SolrClientand 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.SolrServerExceptionUploads the solr config (if one is provided), and initializes or reloads the solr collection with the config. This is done using theLBHttp2SolrClient.- 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.SolrServerExceptionUploads the solr config (if one is provided), and initializes or reloads the solr collection with the config. This is done using theCloudSolrClient.- 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.
-