public DirectoryProviders CreateDirectoryProviders(DocumentMapping classMapping, Configuration cfg, ISearchFactoryImplementor searchFactoryImplementor) { // Get properties string directoryProviderName = GetDirectoryProviderName(classMapping, cfg); IDictionary <string, string>[] indexProps = GetDirectoryProperties(cfg, directoryProviderName); // Set up the directories int nbrOfProviders = indexProps.Length; IDirectoryProvider[] providers = new IDirectoryProvider[nbrOfProviders]; for (int index = 0; index < nbrOfProviders; index++) { string providerName = nbrOfProviders > 1 ? directoryProviderName + "." + index : directoryProviderName; // NB Are the properties nested?? providers[index] = CreateDirectoryProvider(providerName, indexProps[index], searchFactoryImplementor); } // Define sharding strategy IIndexShardingStrategy shardingStrategy; IDictionary <string, string> shardingProperties = new Dictionary <string, string>(); // Any indexProperty will do, the indexProps[0] surely exists. foreach (KeyValuePair <string, string> entry in indexProps[0]) { if (entry.Key.StartsWith(SHARDING_STRATEGY)) { shardingProperties.Add(entry); } } string shardingStrategyName; shardingProperties.TryGetValue(SHARDING_STRATEGY, out shardingStrategyName); if (string.IsNullOrEmpty(shardingStrategyName)) { if (indexProps.Length == 1) { shardingStrategy = new NotShardedStrategy(); } else { shardingStrategy = new IdHashShardingStrategy(); } } else { try { System.Type shardingStrategyClass = ReflectHelper.ClassForName(shardingStrategyName); shardingStrategy = (IIndexShardingStrategy)Activator.CreateInstance(shardingStrategyClass); } catch { // TODO: See if we can get a tigher exception trap here throw new SearchException("Failed to instantiate lucene analyzer with type " + shardingStrategyName); } } shardingStrategy.Initialize(shardingProperties, providers); return(new DirectoryProviders(shardingStrategy, providers)); }
public DirectoryProviders CreateDirectoryProviders(DocumentMapping classMapping, Configuration cfg, ISearchFactoryImplementor searchFactoryImplementor) { // Get properties string directoryProviderName = GetDirectoryProviderName(classMapping, cfg); IDictionary<string, string>[] indexProps = GetDirectoryProperties(cfg, directoryProviderName); // Set up the directories int nbrOfProviders = indexProps.Length; IDirectoryProvider[] providers = new IDirectoryProvider[nbrOfProviders]; for (int index = 0; index < nbrOfProviders; index++) { string providerName = nbrOfProviders > 1 ? directoryProviderName + "." + index : directoryProviderName; // NB Are the properties nested?? providers[index] = CreateDirectoryProvider(providerName, indexProps[index], searchFactoryImplementor); } // Define sharding strategy IIndexShardingStrategy shardingStrategy; IDictionary<string, string> shardingProperties = new Dictionary<string, string>(); // Any indexProperty will do, the indexProps[0] surely exists. foreach (KeyValuePair<string, string> entry in indexProps[0]) { if (entry.Key.StartsWith(SHARDING_STRATEGY)) { shardingProperties.Add(entry); } } string shardingStrategyName; shardingProperties.TryGetValue(SHARDING_STRATEGY, out shardingStrategyName); if (string.IsNullOrEmpty(shardingStrategyName)) { if (indexProps.Length == 1) { shardingStrategy = new NotShardedStrategy(); } else { shardingStrategy = new IdHashShardingStrategy(); } } else { try { System.Type shardingStrategyClass = ReflectHelper.ClassForName(shardingStrategyName); shardingStrategy = (IIndexShardingStrategy) Activator.CreateInstance(shardingStrategyClass); } catch { // TODO: See if we can get a tigher exception trap here throw new SearchException("Failed to instantiate lucene analyzer with type " + shardingStrategyName); } } shardingStrategy.Initialize(shardingProperties, providers); return new DirectoryProviders(shardingStrategy, providers); }