2

I'm using Hibernate Search with Spring Boot. I do not have any special configuration for Hibernate Search. It just shows that warning on application startup. How can I specify hibernate.search.lucene_version?

My SearchService class (the only place Hibernate Search is used):

@Service
public class SearchService {

    private FullTextEntityManager fullTextEntityManager;
    private QueryBuilder queryBuilder;

    @Autowired
    public SearchService(EntityManager entityManager) {
        entityManager = entityManager.getEntityManagerFactory().createEntityManager();
        fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    }

    @PostConstruct
    public void initialize() throws InterruptedException {
        fullTextEntityManager.createIndexer().startAndWait();
        queryBuilder = fullTextEntityManager.getSearchFactory()
                .buildQueryBuilder().forEntity(Post.class).get();
    }

    public List<Post> searchByQuery(String query) {
        org.apache.lucene.search.Query luceneQuery = queryBuilder.phrase()
                .withSlop(5)
                .onField("title")
                .sentence(query)
                .createQuery();
        Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, Post.class);
        return (List<Post>) jpaQuery.setMaxResults(20).getResultList();
    }
}
Mahozad
  • 18,032
  • 13
  • 118
  • 133

2 Answers2

5

In your Spring Boot configuration file, prefix any Hibernate ORM/Hibernate Search property with spring.jpa.properties..

So in an application.properties file:

spring.jpa.properties.hibernate.search.lucene_version LATEST

In an application.yaml file:

spring.jpa.properties:
    hibernate.search:
        lucene_version: LATEST

Use any value that you will deem appropriate instead of LATEST. Available values are the names of constants in org.apache.lucene.util.Version.

See also the documentation about this specific topic in Hibernate Search.

Update

In Hiberante Search 6 this property has become:

spring.jpa.properties.hibernate.search.backend.lucene_version=LATEST

See also the documentation about this specific topic in Hibernate Search 6.

Stefan
  • 12,108
  • 5
  • 47
  • 66
yrodiere
  • 9,280
  • 1
  • 13
  • 35
2

Another solution would be to create hibernate.properties file in the classpath (I placed it beside my application.properties file) and insert hibernate.search.lucene_version LATEST in it.

Mahozad
  • 18,032
  • 13
  • 118
  • 133