0

我正在尝试使用 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;
    }

}

我认为这适用于创建的每条新记录,但我现有的数据呢?有没有办法让我现有的数据用于休眠分面搜索。?

4

1 回答 1

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

        List<YourEntity> entities = super.listAll();
for (YourEntity item : entities) {
   fts.index(item); //manually index 
}
于 2013-10-06T18:28:20.693 回答