- Notifications
You must be signed in to change notification settings - Fork1
A convenience library for Solr/SolrJ
License
redlink-gmbh/solrlib
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
an easy to use solr client, that works embedded or with SolrServer and SolrCloud.
SolrLib aims to ease the use ofApache Solr within Java applications.
Often you want to internally use Solr -SolrLib helps launching up an embedded CoreContainer. The big advantage: Youkeep the core/collection configuration where it belongs - next to the code.If later, you want to switch to using an external Solr Server (classic or SolrCloud), you can do so without code-changes.SolrLib will evendeploy/update your collections on the remote instances.
<dependency> <groupId>io.redlink.solrlib</groupId> <artifactId>solrlib</artifactId> <version>${VERSION}</version></dependency>
SolrLib is split up in several modules:
solrlib-api
solrlib-embedded
solrlib-standalone
solrlib-cloud
For convenience, there is also asolrlib-spring-boot-autoconfigure
module for ease-of-use withinSpring Boot environments.
Cores/collections are registered by using aSolrCoreDescriptor
, e.g. aSimpleCoreDescriptor
:
// Create a core-descriptorCoreDescriptormyCore =newSimpleCoreDescriptor("my-core",Paths.get("/path/to/solr-conf"));// Create SolrCoreContainer and register CoreEmbeddedCoreContainerConfigurationconfig =newEmbeddedCoreContainerConfiguration();config.setHome(solrHome);config.setDeleteOnShutdown(true);SolrCoreContainercoreContainer =newEmbeddedCoreContainer(Collections.singleton(coreDescriptor),config,null);coreContainer.initialize();// ...// retrieve a SolrClienttry (SolrClientsolrClient =coreContainer.getSolrClient(myCore)) {solrClient.ping().getStatus();}
When usingsolrlib-embedded
, an embedded CoreContainer will be launched. There is no directaccess to the Solr webservices or the admin-ui, you can retrieve anSolrClient
to executequeries in your code.
Uponinitialize()
, all registeredCoreDescriptors
will be deployed.EmbeddedCoreContainerConfiguration.setDeleteOnShutdown
controls if solr-home will be deleted uponshutdown.
When usingsolrlib-standalone
,SolrLib connects to an external Solr server via http. Ifthe home-directory is configured, the registered cores are copied there and registered via theSolr Core Admin API. The configuration flagdeployCores
chan further disable this.
Insolrlib-cloud
,SolrLib connects to an SolrCloud ensemble via the provided zookeeper connectionstring.If the configuration flagdeployCores
is set, all registered cores will be deployed to SolrCloudusingCloudSolrClient.uploadConfig
.
NOTE: adding runtime-libraries from thelib
folder is currently not supported!
To useSolrLib in a Spring Boot environment, add the following dependencies to your project:
<dependencies><!-- Spring Boot Autoconfiguration for SolrLib--> <dependency> <groupId>io.redlink.solrlib</groupId> <artifactId>solrlib-spring-boot-autoconfigure</artifactId> <version>${solrlib.version}</version> </dependency><!-- at least on implementation for runtime--> <dependency> <groupId>io.redlink.solrlib</groupId> <artifactId>solrlib-embedded</artifactId> <version>${solrlib.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>io.redlink.solrlib</groupId> <artifactId>solrlib-standalone</artifactId> <version>${solrlib.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>io.redlink.solrlib</groupId> <artifactId>solrlib-cloud</artifactId> <version>${solrlib.version}</version> <scope>runtime</scope> </dependency></dependencies>
The autoconfiguration checks solrlib with the following priority, the first one to match will be used:
- SolrLib Cloud (requires
solrlib.zk-connection
to be set) - SolrLib Standalone (requires
solrlib.base-url
to be set) - SolrLib Embedded (fallback)
All supported configuration properties forSolrLib:
# Used by embedded and standalone# the ${SOLR_HOME} directorysolrlib.home = /path/to/solr/home# This will trigger using solrlib-standalone if available on the classpath# base-url for all solr requestssolrlib.base-url = http://localhost:8983/solr# This will trigger using solrlib-cloud if available on the classpath# ZooKeeper connection stringsolrlib.zk-connection = zookeeper1:8121,zookeeper2:8121# Only used by standalone and cloud# prefix for the remote collection names,# to avoid name-clashes on shared servers.solrlib.collection-prefix =# Only relevant in cloud-modesolrlib.max-shards-per-node = 1# Only used by standalone and cloud# option to disable automatic configuration update/deployment# to remote servers. You might not have the karma to do so.solrlib.deploy-cores = true# Only used by embedded# option to delete the solrlib-home upon shutdownsolrlib.delete-on-shutdown = false
SolrLib is licensed under theApache License 2.0.
About
A convenience library for Solr/SolrJ