SearchConfiguration searchConfiguration,
Properties indexProperties,
XClass clazz,
WorkerBuildContext buildContext) {
// first check on class level
Similarity classLevelSimilarity = null;
// TODO - the processing of the @Similarity annotation is temporary here. The annotation should be removed in Search 5 (HF)
List<XClass> hierarchyClasses = ReflectionHelper.createXClassHierarchy( clazz );
Class<?> similarityClass = null;
for ( XClass hierarchyClass : hierarchyClasses ) {
org.hibernate.search.annotations.Similarity similarityAnnotation = hierarchyClass.getAnnotation( org.hibernate.search.annotations.Similarity.class );
if ( similarityAnnotation != null ) {
Class<?> tmpSimilarityClass = similarityAnnotation.impl();
if ( similarityClass != null && !similarityClass.equals( tmpSimilarityClass ) ) {
throw log.getMultipleInconsistentSimilaritiesInClassHierarchyException( clazz.getName() );
}
else {
similarityClass = tmpSimilarityClass;
}
classLevelSimilarity = ClassLoaderHelper.instanceFromClass(
Similarity.class,
similarityClass,
"Similarity class for index " + directoryProviderName
);
}
}
// now we check the config
Similarity configLevelSimilarity = getConfiguredPerIndexSimilarity(
directoryProviderName,
indexProperties,
buildContext
);
if ( classLevelSimilarity != null && configLevelSimilarity != null ) {
throw log.getInconsistentSimilaritySettingBetweenAnnotationsAndConfigPropertiesException(
classLevelSimilarity.getClass().getName(),
configLevelSimilarity.getClass().getCanonicalName()
);
}
else if ( classLevelSimilarity != null ) {
return classLevelSimilarity;
}