我似乎在 hibernate 搜索的初始化过程中遗漏了一些东西。
我的 mysql 数据库表包含一些现有的行,这些行似乎没有作为结果的一部分返回
我在启动后通过应用程序添加的任何新行似乎都在 hibernate 搜索中返回
我需要返回所有行,包括表中已经存在的行,我需要添加什么才能得到它?
这是我用来查询的代码段
// get the full text entity manager
FullTextEntityManager fullTextEntityManager=Search.getFullTextEntityManager(entityManager);
//create query using hibernate query DSL
QueryBuilder queryBuilder=fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Entity.class).get();
// actual query
Query query=queryBuilder.keyword()
.onFields("col1","col2","col3")
.matching(searchKeyword)
.createQuery();
//wrap Lucene query in hibernate query object
FullTextQuery jpaQuery=fullTextEntityManager.createFullTextQuery(query, Entity.class);
return jpaQuery.getResultList();
最佳答案
您需要运行 mass indexer将所有这些实体添加到已添加/更新的索引中,而 Hibernate Search 尚未(尚未)启用。
这将从数据库中获取所有实体并更新相应的索引。最简单的形式是这样完成的:
fullTextEntityManager
.createIndexer( Entity.class )
.startAndWait();
引用指南详细描述了微调的所有选项。
关于java - hibernate 搜索,现有数据不可搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34147336/