//TODO check if caching this work for the last n list of classes makes a perf boost
if ( classes == null || classes.length == 0 ) {
// empty classes 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 ( DocumentBuilder builder : builders.values() ) {
searcherSimilarity = checkSimilarity( searcherSimilarity, builder );
if ( builder.getIdKeywordName() != null ) {
idFieldNames.add( builder.getIdKeywordName() );
allowFieldSelectionInProjection = allowFieldSelectionInProjection && builder.allowFieldSelectionInProjection();
}
final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy()
.getDirectoryProvidersForAllShards();
populateDirectories( directories, directoryProviders );
}
classesAndSubclasses = null;
}
else {
Set<Class<?>> involvedClasses = new HashSet<Class<?>>( classes.length );
Collections.addAll( involvedClasses, classes );
for ( Class<?> clazz : classes ) {
DocumentBuilder<?> builder = builders.get( clazz );
if ( builder != null ) {
involvedClasses.addAll( builder.getMappedSubclasses() );
}
}
for ( Class clazz : involvedClasses ) {
DocumentBuilder 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();
}