We have a parent-child relationship in our indexed domain objects, and all child and parent fields are in the same Lucene index.
Specifically, we have:
- PhysicalItem extends AbstractItem
- DigitalItem extends AbstractItem
- IntellectualItem extends AbstractItem
The concrete classes all have the identical annotation:
@Indexed(index = "Item")
We are including facets in our search, and a search needs to return all item types (i.e., instances of PhysicalItem, DigitalItem and IntellectualItem).
However, for constructing the QueryBuilder in order to construct a FacetingRequest, we can only specify a single entity. This can't be AbstractItem as it's abstract, so we are currently - arbitrarily - picking one of the subclasses.
QueryBuilder builder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(IntellectualItem.class).get();
For a search, this returns identical facet results regardless which subclass I use in forEntity() but the technique seems a bit odd and fragile. I suspect this is currently working fine because all of the subclasses are using the same Lucene index.
So, my questions are:
1. Is this approach indeed a bit suspect?
2. Is there a better approach? (I see that there is a TODO in QueryContextBuilder that there should be a forEntities() method written)
I guess if I wanted to be really safe I could construct separate faceting requests for each subclass, but this seems like a reasonable amount of bother...