public static DirectoryProvider<?> createDirectoryProvider( String directoryProviderName, Properties indexProps, WorkerBuildContext context) { String className = indexProps.getProperty("directory_provider", ""); String maybeShortCut = className.toLowerCase(); DirectoryProvider<?> provider; // try and use the built-in shortcuts before loading the provider as a fully qualified class // name if (defaultProviderClasses.containsKey(maybeShortCut)) { String fullClassName = defaultProviderClasses.get(maybeShortCut); provider = ClassLoaderHelper.instanceFromName( DirectoryProvider.class, fullClassName, DirectoryProviderFactory.class, "directory provider"); } else { provider = ClassLoaderHelper.instanceFromName( DirectoryProvider.class, className, DirectoryProviderFactory.class, "directory provider"); } try { provider.initialize(directoryProviderName, indexProps, context); } catch (Exception e) { throw new SearchException( "Unable to initialize directory provider: " + directoryProviderName, e); } return provider; }
@Override public IndexReader openIndexReader() { // #getDirectory must be invoked each time as the underlying directory might "dance" as in // org.hibernate.search.store.impl.FSSlaveDirectoryProvider Directory directory = directoryProvider.getDirectory(); try { return IndexReader.open(directory, true); } catch (IOException e) { throw new SearchException("Could not open index \"" + indexName + "\"", e); } }