Joining Two Indexes


#1

We are having two index corresponding to two entities:

@Entity
@Table(name = “A”)
@Indexed(index=“a”)
public class A{
}

@Entity
@Table(name = “B”)
@Indexed(index=“B”)
public class B{
}

Is it possible to create a join in the query to retrieve result from both index by joining on some common identifier?


#2

You can target both indexes in a single query, so as to retrieve results of type A or B in the same result list:

FullTextQuery query = fullTextEntityManager.createQuery( luceneQuery, A.class, B.class );
List<Object> results = query.getResultList(); // Contains some objects of type A and some objects of type B

But if you really want a join, then no, Hibernate Search does not provide that feature. Multi-entity queries are generally achieved with @IndexedEmbedded, by embedding other entities in an entity’s index. See this section of the documentation.