【问题标题】:hibernate search, existing data not searchable休眠搜索,现有数据不可搜索
【发布时间】:2015-12-08 03:13:19
【问题描述】:

我似乎在休眠搜索的初始化过程中遗漏了一些东西。
我的 mysql 数据库表包含一些现有行,这些行似乎没有作为结果的一部分返回
我在启动后通过应用程序添加的任何新行似乎都会在休眠搜索中返回

我需要返回所有行,包括表中已经存在的行,我需要添加什么来获取它?

这是我用来查询的代码部分

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

【问题讨论】:

    标签: java mysql hibernate lucene hibernate-search


    【解决方案1】:

    您需要运行 mass indexer 以将所有这些实体添加到索引中,这些实体在 Hibernate Search 未(尚未)启用时已添加/更新。

    这将从数据库中获取所有实体并更新相应的索引。在最简单的形式中,它是这样完成的:

    fullTextEntityManager
        .createIndexer( Entity.class )
        .startAndWait();
    

    参考指南详细描述了微调的所有选项。

    【讨论】:

    • 谢谢你,成功了。我想我应该是 RTFM :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多