在多个 class 层次结构上进行 Hibernate 搜索
Hibernate search on multiple class hierarchy
让我们提供 class 示例:
抽象class超级父{
超级父字段1;
}
抽象class Parent extends SuperParent {
父字段1;
}
class ImplementaingClass1 扩展父级 {
// 我只想索引 parentField1
}
class ImplementingClass2 extends Parent {
// 我只想索引 superParentField1
}
以及这些的变体。
在休眠搜索中处理此问题的最佳方法是什么?所以我可以在任何给定 class 的任何字段上进行搜索。我是否需要覆盖实现 class 上的字段并在那里添加注释?没有别的办法吗?
覆盖 getter 并在覆盖的 getter 上添加 @Field
注释:
abstract class SuperParent { superParentField1; }
abstract class Parent extends SuperParent { parentField1; }
@Indexed
class ImplementingClass1 extends Parent {
@Override
@Field(... stuff ...)
SomeType getParentField1() {
return super.getParentField1();
}
}
@Indexed
class ImplementingClass2 extends Parent {
@Override
@Field(... stuff ...)
SomeType getSuperParentField1() {
return super.getSuperParentField1();
}
}
或者,使用 programmatic mapping。如果您有多个具有此类约束的字段,这将尤其重要。
让我们提供 class 示例:
抽象class超级父{ 超级父字段1; }
抽象class Parent extends SuperParent { 父字段1; }
class ImplementaingClass1 扩展父级 { // 我只想索引 parentField1 }
class ImplementingClass2 extends Parent { // 我只想索引 superParentField1 }
以及这些的变体。
在休眠搜索中处理此问题的最佳方法是什么?所以我可以在任何给定 class 的任何字段上进行搜索。我是否需要覆盖实现 class 上的字段并在那里添加注释?没有别的办法吗?
覆盖 getter 并在覆盖的 getter 上添加 @Field
注释:
abstract class SuperParent { superParentField1; }
abstract class Parent extends SuperParent { parentField1; }
@Indexed
class ImplementingClass1 extends Parent {
@Override
@Field(... stuff ...)
SomeType getParentField1() {
return super.getParentField1();
}
}
@Indexed
class ImplementingClass2 extends Parent {
@Override
@Field(... stuff ...)
SomeType getSuperParentField1() {
return super.getSuperParentField1();
}
}
或者,使用 programmatic mapping。如果您有多个具有此类约束的字段,这将尤其重要。