//TODO cleanup: this logic to select the Similarity is too complex, should likely be done in a previous phase
final Map<Class<?>, EntityIndexBinder> documentBuildersIndexedEntities = factoryState.getIndexBindingForEntity();
for ( Entry<Class<?>, EntityIndexBinder> entry : documentBuildersIndexedEntities.entrySet() ) {
Class<?> clazz = entry.getKey();
EntityIndexBinder entityMapping = entry.getValue();
Similarity entitySimilarity = entityMapping.getSimilarity();
if ( entitySimilarity == null ) {
//might have been read from annotations, fill the missing information in the EntityIndexBinder:
entitySimilarity = entityMapping.getDocumentBuilder().getSimilarity();
if ( entitySimilarity != null ) {
MutableEntityIndexBinding newMapping = new MutableEntityIndexBinding( entityMapping.getSelectionStrategy(), entitySimilarity, entityMapping.getIndexManagers() );
newMapping.setDocumentBuilderIndexedEntity( entityMapping.getDocumentBuilder() );
entityMapping = newMapping;
documentBuildersIndexedEntities.put( clazz, entityMapping );
}
}
IndexManager[] indexManagers = entityMapping.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."
);