Issue
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();
}
}
Solution
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.
Answered By - yrodiere