//TODO check if caching this work for the last n list of indexedTargetedEntities makes a perf boost
if ( indexedTargetedEntities.size() == 0 ) {
// empty indexedTargetedEntities array means search over all indexed enities,
// but we have to make sure there is at least one
if ( builders.isEmpty() ) {
throw new HibernateException(
"There are no mapped entities. Don't forget to add @Indexed to at least one class."
);
}
for ( DocumentBuilderIndexedEntity builder : builders.values() ) {
searcherSimilarity = checkSimilarity( searcherSimilarity, builder );
if ( builder.getIdKeywordName() != null ) {
idFieldNames.add( builder.getIdKeywordName() );
allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
}
populateDirectories( targetedDirectories, builder );
}
classesAndSubclasses = null;
}
else {
Set<Class<?>> involvedClasses = new HashSet<Class<?>>( indexedTargetedEntities.size() );
involvedClasses.addAll( indexedTargetedEntities );
for ( Class<?> clazz : indexedTargetedEntities ) {
DocumentBuilderIndexedEntity<?> builder = builders.get( clazz );
if ( builder != null ) {
involvedClasses.addAll( builder.getMappedSubclasses() );
}
}
for ( Class clazz : involvedClasses ) {
DocumentBuilderIndexedEntity builder = builders.get( clazz );
//TODO should we rather choose a polymorphic path and allow non mapped entities
if ( builder == null ) {
throw new HibernateException( "Not a mapped entity (don't forget to add @Indexed): " + clazz );
}
if ( builder.getIdKeywordName() != null ) {
idFieldNames.add( builder.getIdKeywordName() );
allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
}