//TODO cleanup: this logic to select the Similarity is too complex, should likely be done in a previous phase
final Map<Class<?>, EntityIndexBinding> documentBuildersIndexedEntities = factoryState.getIndexBindings();
for ( Entry<Class<?>, EntityIndexBinding> entry : documentBuildersIndexedEntities.entrySet() ) {
Class<?> clazz = entry.getKey();
EntityIndexBinding entityIndexBinding = entry.getValue();
Similarity entitySimilarity = entityIndexBinding.getSimilarity();
if ( entitySimilarity == null ) {
//might have been read from annotations, fill the missing information in the EntityIndexBinder:
entitySimilarity = entityIndexBinding.getDocumentBuilder().getSimilarity();
if ( entitySimilarity != null ) {
MutableEntityIndexBinding newMapping = buildTypeSafeMutableEntityBinder(
entityIndexBinding,
entitySimilarity
);
entityIndexBinding = newMapping;
documentBuildersIndexedEntities.put( clazz, entityIndexBinding );
}
}
IndexManager[] indexManagers = entityIndexBinding.getIndexManagers();
for ( IndexManager indexManager : indexManagers ) {
Similarity indexSimilarity = indexManager.getSimilarity();
if ( entitySimilarity != null && indexSimilarity == null ) {
indexManager.setSimilarity( entitySimilarity );
}
else if ( entitySimilarity != null && ! entitySimilarity.getClass().equals( indexSimilarity.getClass() ) ) {
throw new SearchException(
"Multiple entities are sharing the same index but are declaring an " +
"inconsistent Similarity. When overriding default Similarity make sure that all types sharing a same index " +
"declare the same Similarity implementation."
);