【发布时间】:2018-07-02 12:07:10
【问题描述】:
我将三个类定义为:
1)类别类:-
@Entity
@Table(name = "CATEGORY")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Indexed
public class Category {
@Id
@GeneratedValue
private Long id;
@Field(index = Index.YES, store = Store.YES, analyzer = @Analyzer(definition = "ngram"))
private String categoryName;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "categoryId", referencedColumnName = "id")
@LazyCollection(LazyCollectionOption.TRUE)
@IndexedEmbedded
private List<SubCategory> subCategories;
private Long creationTime;
private Long updationTime;
}
2) SubCategory 类:-
@Entity
@Table(name = "SUB_CATEGORY")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Indexed
public class SubCategory {
@Id
@GeneratedValue
private Long id;
@Field(index = Index.YES,store = Store.YES,analyzer = @Analyzer(definition = "ngram1"))
private String subCategoryName;
@Field(index = Index.YES,store = Store.YES)
private Long categoryId;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "subCategoryId", referencedColumnName = "id")
@LazyCollection(LazyCollectionOption.TRUE)
@IndexedEmbedded
private List<Pages> pages;
private Long creationTime;
}
3) 页面类:-
@Entity
@Table(name = "PAGES")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Indexed
public class Pages {
@Id
@GeneratedValue
private Long id;
@Field(index = Index.YES,store = Store.YES,analyzer = @Analyzer(definition = "ngram2"))
private String pageName;
@Field(index = Index.YES,store = Store.YES,analyzer = @Analyzer(definition = "ngram2"))
private String pageDescription;
@Field(index = Index.YES,store = Store.YES,analyzer = @Analyzer(definition = "ngram2"))
private Long subCategoryId;
private Long creationTime;
}
现在数据定义如下:-
Category SubCategory Pages
-------- ------------ -------
Vehicle Car BMW
Electricals MotorCycle Hero
........... ........ Audi
........... ........ ......
Lapzz Laptop ......
Dell
现在我被困在获取将使用休眠搜索在所有三个类中搜索的查询(即 - 如果我搜索 Lap*)我应该从类别、子类别和页面中获取结果,并且只有与查询匹配的行不是Category 的完整对象。
例如,当我搜索 Lap* 时,我应该在结果集中获得类别中包含 Lapzz 的行和子类别中包含笔记本电脑的行。 请帮我找到这个解决方案。
【问题讨论】:
-
你说的“行”是什么意思?在您的结果中,您是否想要混合使用
Category、SubCategory和Pages对象,具体取决于匹配的对象?或者您是否只想要Page对象,即使您的条件与某个类别匹配(在这种情况下,您将获得匹配类别的所有页面)? -
我想要类别、子类别和页面的混合。假设我搜索一个查询,那么结果应该包含所有三个表数据的混合。
标签: orm hibernate-mapping hibernate-search hibernate-query