未指定hibernate.search.lucene_version:使用LUCENE_CURRENT

时间:2018-07-04 12:42:03

标签: java spring hibernate spring-boot hibernate-search

我在Spring Boot中使用Hibernate Search。我没有Hibernate Search的任何特殊配置。它仅显示应用程序启动时的警告。如何指定hibernate.search.lucene_version?

我的SearchService类(使用Hibernate Search的唯一位置):

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

2 个答案:

答案 0 :(得分:2)

在您的Spring Boot配置文件中,为任何Hibernate ORM / Hibernate Search属性添加spring.jpa.properties.前缀。

因此在application.properties文件中:

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

application.yaml文件中:

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

使用您认为合适的任何值代替LATEST。可用值是org.apache.lucene.util.Version中常量的名称。

另请参阅the documentation about this specific topic in Hibernate Search

答案 1 :(得分:0)

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