Hibernate搜索在一个环境中工作,但不在其他环境中工作

Hibernate搜索在一个环境中工作,但不在其他环境中工作,hibernate,hibernate-search,Hibernate,Hibernate Search,这是我第一次尝试hibernate搜索,所以我对它还不熟悉。我有一个实体,我把它编入了索引,这样我就可以搜索名称字段。它在我的机器上运行,每当我的队友搜索任何东西时,它都会返回0个结果,尽管还有其他hibernate搜索部分在其末尾运行良好 我使用的查询如下所示 public List<Agency> findByText(String text) { FullTextEntityManager ftManager = org.hibernate.search.jpa

这是我第一次尝试hibernate搜索,所以我对它还不熟悉。我有一个实体,我把它编入了索引,这样我就可以搜索名称字段。它在我的机器上运行,每当我的队友搜索任何东西时,它都会返回0个结果,尽管还有其他hibernate搜索部分在其末尾运行良好

我使用的查询如下所示

public List<Agency> findByText(String text) {
        FullTextEntityManager ftManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);
    try {
        return ftManager
                .createFullTextQuery(
                        new MultiFieldQueryParser(new String[] { "name" }, new StandardAnalyzer()).parse(text
                                + "*"), Agency.class).getResultList();
    } catch (ParseException e) {
        log.error("Exception has occurred when trying to execute search", e);
    }

    return Collections.emptyList();
}

我建议您使用检查Lucene索引。这将允许您查看索引的内容,以及您可以期望返回的内容

这可能是因为您没有正确设置事务,并且数据库更改没有反映在索引中

此外,如果您刚刚使用Hibernate搜索,那么查看索引实际包含的内容会很有趣,也很有启发性

@Entity
@Indexed
@Table(
        name="Agency",
        uniqueConstraints=
            @UniqueConstraint(columnNames={"id", "name"})
    )
public class Agency {

    @Id
    @GeneratedValue
    private Long id;

    @Field(index = Index.TOKENIZED, store = Store.NO)
    private String name;