简体   繁体   中英

hibernate.search.lucene_version was not specified: using LUCENE_CURRENT

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();
    }
}

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 .

另一个解决方案是在类路径中创建hibernate.properties文件(我将其放置在application.properties文件旁边),然后在其中插入hibernate.search.lucene_version LATEST

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM