Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

This project contains a simple example how to integrate vind with spring boot applications

Notifications You must be signed in to change notification settings

RBMHTechnology/how-to-vind-with-spring-boot

Repository files navigation

Vind in Spring Boot Applications

This repo shows how to integrate VIND in Spring Boot applications. It is not about the functionality of VIND itself, which is exhaustively described in the repo and the linked feature documentation. It contains a simple demo application including some best practices regarding development, testing, dependency management etc.

The demo

The demo shows how to create a simple search scenario using VIND. It indexes 3 documents on a local solr server and provides a simple API to issue queries.

Run the demo

  1. start local vind server: docker-compose up
  2. start application ./gradlew bootRun

Use the search webservice

The search webservice is described via Open API spec. Some simple request:

  • Search for first: curl -X GET "http://localhost:8080/search?q=first&limit=10" -H "accept: application/json"
  • Search for articles of the last 24 hours: curl -X GET "http://localhost:8080/search?range=PAST_DAY&limit=10" -H "accept: application/json"
  • Search for articles with tag cat: curl -X GET "http://localhost:8080/search?tag=cat&limit=10" -H "accept: application/json"

The application

Dependency and Spring AutoConfiguration

If you use VIND you use (currently) Solr, which mean that you have to deal with some Spring Magic (as Spring Boot has some support of Solr as well, which leads to version conflicts). Therefore:

  • force the VIND related solr-core and solrj-core version (you can look this up in the VIND github repo easily)
  • exclude Solr Auto Configuration for the application @SpringBootApplication(exclude = SolrAutoConfiguration.class)
  • try to use embedded solr server with caution (see the paragraph about testing)

Search Server Connection

The simplest way to use a VIND search server is to outcheck a bean, like in VindConfiguration. In the demo case a local search server is linked.

Development and local setup

Run local VIND server

The easiest way to run a local VIND server is to use the vind docker image. The repository includes a docker-compose file that starts a solr server on localhost:8983/solr and creates a vind core named localdocs.

Create a VIND collection on a running solr cloud

VIND includes a collection management tool, that allows to create and update vind collections with a single command line call. The tool is described here.

Indexing

The demo shows how to index articles by using a simple document factory. Here the fields that are used for indexing are defined. In addition helper functions for mapping from and to VIND documents are implemented. The indexing istelf is triggered in application start (in the main).

Search

The search is encapsulated in a service. The example shows how to use fulltext search, filters (term and time range) and how to generate facets.

Testing

Simple Unit Tests

A simple unit test is shown here. VIND provides a embedded server for testing. But be aware that you might end up in dependency hell if you want to use it for more complex test (that uses Spring Boot context e.g.). Therefore we suggest to use testcontainers.

Complex tests using VIND testcontainers

In a special test we show how a specific VIND testcontainer (based on Docker testcontainers) can be used as a proper VIND backend for integration tests. This is the preferable usage, as there are quite some dependency issues with Embedded Solr and Spring Boot, as already mentioned. If you want to try the test and on mac, please be sure that docker is running. Note, that the testcontainer is currently only available as snapshot, but there will be a release soon.

Heath Check

In order to check the health of the VIND endpoint you can use the VIND built in status check and expose it as health indicator. In the demo you can check the endpoint on http://localhost:8082/actuator/health.

About

This project contains a simple example how to integrate vind with spring boot applications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages