使用hibernate搜索在同一索引中索引不相关的实体

使用hibernate搜索在同一索引中索引不相关的实体,hibernate,lucene,domain-driven-design,hibernate-search,Hibernate,Lucene,Domain Driven Design,Hibernate Search,在我们的域模型中,我们非常积极地使用聚合,即我们不通过jpa关系连接所有类,而是使用我们可以查询相关对象的服务。所以,假设我们有两个示例类,Person和Workplace,它们通过引用而不是直接对象关系相关联 public class Person { int id; String name; } public class Workplace { int id; String name; List<int> personId; } 公共类人物{ int-id

在我们的域模型中,我们非常积极地使用聚合,即我们不通过jpa关系连接所有类,而是使用我们可以查询相关对象的服务。所以,假设我们有两个示例类,Person和Workplace,它们通过引用而不是直接对象关系相关联

public class Person {
  int id;
  String name;
}

public class Workplace {
  int id;
  String name;
  List<int> personId;
}
公共类人物{
int-id;
字符串名;
}
公营工作场所{
int-id;
字符串名;
列出人名;
}
现在,我们想构建一个Hibernate搜索索引,它应该为来自Person和Workplace的字段建立索引。这是通过Hibernate搜索实现的吗?还是我们必须使用自己的Lucene索引器并自行维护Hibernate搜索对索引执行的所有维护


是否还有其他的解决方案需要考虑?

使用Hibernate搜索,你可以很容易地创建一个包含两个索引的索引,或者每个实体可以有两个索引,但作为单个索引查询它们。

@Indexed @Entity
public class Person {
   int id;
   @Field
   String name;
}

@Indexed @Entity
public class Workplace {
   int id;
   @Field
   String name;
   List<int> personId;
}
或者只是所有索引类型:

FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( q );
List list = fullTextQuery.list();

使用Hibernate搜索,您可以轻松地创建一个包含这两个索引的索引,或者您可以有两个索引,每个实体一个索引,但可以像查询单个索引一样进行查询

@Indexed @Entity
public class Person {
   int id;
   @Field
   String name;
}

@Indexed @Entity
public class Workplace {
   int id;
   @Field
   String name;
   List<int> personId;
}
或者只是所有索引类型:

FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( q );
List list = fullTextQuery.list();

我试过这个,效果很好。但问题是结果排序不正确。列出所有的人,然后列出所有的工作场所。我试过这个,效果很好。但问题是结果排序不正确。列出所有工作场所,然后列出所有工作场所。