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>0</version>
</dependency>

Use SolrJ in your application

You can inject the SolrClient bean provided by the extension to interact with Solr. 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 customize the dev service using configuration properties.

Observability

All interactions with Solr are logged at the DEBUG level, so 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, an 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: QUARKUS_SOLR_HEALTH_ENABLED

boolean

true

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: QUARKUS_SOLR_DEVSERVICES_ENABLED

boolean

true

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: QUARKUS_SOLR_DEVSERVICES_IMAGE_NAME

string

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_SOLR_DEVSERVICES_PORT

int

The name of the collection to be created in Solr

If not defined, a collection names "dummy" will be created

Environment variable: QUARKUS_SOLR_DEVSERVICES_COLLECTION

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: QUARKUS_SOLR_DEVSERVICES_CONFIGURATION

string

The value of the label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services looks for a container with the quarkus-dev-service-solr label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise, it starts a new container with the quarkus-dev-service-solr label set to the specified value.

This property is used when you need multiple shared Vault instances.

Environment variable: QUARKUS_SOLR_DEVSERVICES_SERVICE_NAME

string

solr

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 quarkus-dev-service-solr label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_SOLR_DEVSERVICES_SHARED

boolean

true

Should solr could be used?

Environment variable: QUARKUS_SOLR_CLOUD

boolean

false

URL on which Solr is running.

If multiple URLs are given, the first one is used as the base URL and the others are used for failover. If solr could is not used, only one URL can be defined.

Environment variable: QUARKUS_SOLR_URL

list of string

required