Hibernate Faceted搜索现有数据

时间:2013-09-29 12:33:19

标签: hibernate search hibernate-search

我正在尝试使用Hibernate Search实现分面搜索,我发现要在你的模态中启用分面搜索,你需要添加@Field注释,如下面的例子

@Entity
@Indexed(index = "index/books")
public class Book {
    private Long id;
    private String title;
    private String author;
    private String category;
    private int price;

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    @Field(name = "title", analyze = Analyze.YES, store = Store.YES)
    public String getTitle() {
        return title;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public void setAuthor(final String author) {
        this.author = author;
    }

    @Field(analyze = Analyze.NO, store = Store.YES)
    public String getAuthor() {
        return author;
    }

    @Field(analyze = Analyze.NO, store = Store.YES)
    public String getCategory() {
        return category;
    }

    public void setCategory(final String category) {
        this.category = category;
    }

    @Field(analyze = Analyze.NO, store = Store.YES)
    public int getPrice() {
        return price;
    }

    public void setPrice(final int price) {
        this.price = price;
    }

}

我认为这对于每个创建的新记录都有效,但我现有的数据呢?有没有办法为hibernate分面搜索启用现有数据。

1 个答案:

答案 0 :(得分:0)

            FullTextSession fts =
   org.hibernate.search.Search.getFullTextSession(getSession());

        List<YourEntity> entities = super.listAll();
for (YourEntity item : entities) {
   fts.index(item); //manually index 
}