【问题标题】:Lucene indexes not persisting in Hibernate SearchLucene 索引未在 Hibernate Search 中保留
【发布时间】:2017-10-04 08:48:57
【问题描述】:

我有一个@Indexed 实体,我在其上执行休眠搜索。我按照以下步骤操作:

  1. 通过 Hibernate 保持实体。
  2. 使用休眠搜索进行搜索。 (有效)

但是,一旦我重新启动我的应用程序服务器。我无法搜索最近持久化的实体。我无法理解这里发生了什么。我认为我的 lucene 索引正在生成但没有持久化。

任何对正确方向的帮助都会有很大帮助。

【问题讨论】:

  • 当您说“我无法搜索”时,您的意思是查询不会返回任何结果,对吗?不是说它们只返回空值,或者抛出某种异常?而且我认为日志中也没有任何错误?

标签: hibernate jpa lucene hibernate-search


【解决方案1】:

检查您是否正确配置了目录提供程序:

  1. hibernate.search.default.directory_provider 应该根本不设置或设置为 filesystemlocal-heap(以前的ram)表示不持久,在任何情况下都不应该在生产中使用,除非你真的知道自己在做什么。
  2. hibernate.search.default.indexBase 应设置为文件系统上目录的路径。我认为默认是当前工作目录,如果你从两个不同的目录启动你的应用程序,就好像索引丢失了一样。

https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#_configuration

【讨论】:

  • hibernate.search.default.directory_provider=filesystem hibernate.search.default.indexBase=D:\\Tool\\indexes 我正在使用这些配置值。目录是在应用程序开始时创建的,修改日期也会在我坚持一个值时更新。但是,通过 Luke 检查时没有列出索引。
  • @gschambial 你没有按索引设置吗?喜欢hibernate.search.MyIndexName.directory_provider
  • 不,我有所有索引的全局设置。
  • 没错!但是,我想还有其他问题。我得到了一些线索。最近,我添加了 JUnit 测试用例,其中我创建了一个内存数据源,现在这个数据源覆盖了我的原始数据源,我知道为什么。我正在调查它。我想这不是休眠搜索的问题,而是一些配置问题。
【解决方案2】:

如果您有时间路径,则需要重新索引您的实体。

这是一个使用 SpringBoot 的示例:

 @Component
public class BuildSearchIndex
        implements ApplicationListener<ApplicationReadyEvent> {

    @PersistenceContext
    private EntityManager entityManager;

    /**
     * Create an initial Lucene index for the data already present in the
     * database.
     * This method is called when Spring's startup.
     */
    @Transactional
    @Override
    public void onApplicationEvent(final ApplicationReadyEvent event) {


        try {
            FullTextEntityManager fullTextEntityManager =
                    Search.getFullTextEntityManager(entityManager);
            fullTextEntityManager.createIndexer().startAndWait();
        } catch (InterruptedException e) {
            System.out.println(
                    "An error occurred trying to build the serach index: " +
                            e.toString());
        }
        return;
    }


}

【讨论】:

    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多