Quarkus Solr
Apache Solr is the blazing-fast, open source, multi-modal search platform built on the full-text, vector, and geospatial search capabilities of Apache Lucene. This extension provides integration with Solr, allowing you to easily add search capabilities to your Quarkus application.
It provides the following features:
-
Solr as a dev-service for local development
-
Provide SolrJ beans for interacting with Solr
-
Native compilation support
-
Integration with Quarkus observability stack (health, metrics, logging)
Installation
If you want to use this extension, you need to add the io.quarkiverse.solr:quarkus-solr extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.solr</groupId>
<artifactId>quarkus-solr</artifactId>
<version>1.0.3</version>
</dependency>
Use SolrJ in your application
You can inject the SolrClient bean provided by the extension to interact with Solr.
Each class will get its own instance of SolrClient (scope is @Dependent), so you can safely add custom configuration to it if needed.
For example:
import org.apache.solr.client.solrj.SolrClient;
@ApplicationScoped
public class SolrService {
@Inject
SolrClient solrClient;
public SolrDocumentList query(String query) throws SolrServerException, IOException {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(query);
return solrClient.query("collectionName", solrQuery).getResults();
}
}
Check the SolrJ documentation for more details on how to use the SolrClient to Query and Index documents in Solr.
Dev Services for Solr
The extension provides a dev service for Solr. This allows you to easily run a Solr instance in a container during development.
By default, the dev service will start a Solr instance with a single collection named dummy. You can further customize the dev service
Observability
All interactions with Solr are logged at the DEBUG level, request and response details are logged at TRACE level.
You can enable DEBUG logging for the io.quarkiverse.solr package to see the details of the interactions.
If you add quarkus-smallrye-health or quarkus-micrometer-registry-prometheus to your application, a health check and metrics will be automatically provided for the Solr client.
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
|---|---|---|
Is solr health check enabled Environment variable: |
boolean |
|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a solr instance when running in Dev or Test mode and when Docker is running. Environment variable: |
boolean |
|
The container image name to use, for container based DevServices providers. If not set, the default solr image in the version of solrj will be used Environment variable: |
string |
|
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
The name of the collection to be created in Solr If not defined, a collection names "dummy" will be created Environment variable: |
string |
|
Custom configuration to be used. Must be a directory on the classpath containing at least a solrconfig.xml If not set, default configuration of Solr docker container is used Environment variable: |
string |
|
The value of the label attached to the started container. This property is used when This property is used when you need multiple shared Solr instances. Environment variable: |
string |
|
Indicates if the instance managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services starts a new container. The discovery uses the Container sharing is only used in dev mode. Environment variable: |
boolean |
|
One or more Solr URLs, which the client then uses to send HTTP requests to Solr. These URLS must point to the root Solr path (i.e. "/solr"). If multiple URLs are configured, it is assumed that Solr Cloud Mode is used and these URLs are used to fetch information about the layout and health of the Solr cluster. If only one URL is defined, the URLs is used to send user-provided requests using Environment variable: |
list of string |
required |
Default collection to be used Most SolrClient methods allow users to specify the collection or core they wish to query, etc. as a String parameter. However, continually specifying this parameter can become tedious, especially for users who always work with the same collection. Users can avoid this pattern by specifying a "default" collection If specified SolrClients will use this default for making requests whenever a collection or core is needed (and no overriding value is specified) Environment variable: |
string |
|
Should HTTP 1.1 be used instead of HTTP/2? If not set, HTTP/2 is used by default Environment variable: |
boolean |
|
Request timeout in milliseconds If not set, idle timeout is used Environment variable: |
long |
|
Idle timeout in milliseconds If not set, Environment variable: |
long |
|
Connection timeout in milliseconds If not set, Environment variable: |
long |
|
Should the client follow redirects? If not set, redirect are not followed Environment variable: |
boolean |
|
Maximal number of connections per host If not set, Environment variable: |
int |
|
The username Environment variable: |
string |
required |
The password Environment variable: |
string |
required |
The proxy host Environment variable: |
string |
required |
The proxy port Environment variable: |
int |
|
Is this a socks4 proxy? Environment variable: |
boolean |
|
Is this proxy using HTTPS Environment variable: |
boolean |
|
Force SolrCloud mode If set, it is assumed that Solr Cloud Mode is used even if only one Environment variable: |
boolean |
|
Zookeeper client timeout in milliseconds Only relevant if Solr Cloud Mode is used even. If not set, Environment variable: |
int |
|
Zookeeper connection timeout in milliseconds Only relevant if Solr Cloud Mode is used. If not set, Environment variable: |
int |
|
Can Zookeepers ACL be used Only relevant if Solr Cloud Mode is used. See documentation for details. If not set,SolrJ’s default value (true) is used. Environment variable: |
boolean |
|
Cache ttl for cached objects in seconds Only relevant if Solr Cloud Mode is used. If not set,SolrJ’s default value (60s) is used. Environment variable: |
int |
|
Number of parallel collection state refresh operations to run in parallel Only relevant if Solr Cloud Mode is used. If not set,SolrJ’s default value (5) is used. Environment variable: |
int |
|
Time to wait to re-fetch the state after getting the same state version from Zookeeper in milliseconds Only relevant if Solr Cloud Mode is used. If not set,SolrJ’s default value (3000) is used. Environment variable: |
long |
|
Should shard updates be sent in parallel Only relevant if Solr Cloud Mode is used. When an UpdateRequest affects multiple shards, CloudSolrClient splits it up and sends a request to each affected shard. This setting chooses whether those sub-requests are sent serially or in parallel. If not set,SolrJ’s default value ('true') is used. Environment variable: |
boolean |