public bool Reload(IndexingConfiguration config) { // If we have a directory and the index container has not changed, we don't need to reload. // We don't want to reload the index unless necessary. var newStorageAccountConnectionString = config.StoragePrimary; var newIndexContainerName = config.IndexContainer; if (_directory != null && newStorageAccountConnectionString == _storageAccountConnectionString && newIndexContainerName == _indexContainerName) { return(false); } _storageAccountConnectionString = newStorageAccountConnectionString; _indexContainerName = newIndexContainerName; _logger.LogInformation("Recognized index configuration change."); var storageAccount = CloudStorageAccount.Parse(_storageAccountConnectionString); _logger.LogInformation( "Reloading index with new settings. Storage Account Name = {StorageAccountName}, Container = {IndexContainerName}", storageAccount, _indexContainerName); var stopwatch = Stopwatch.StartNew(); AzureDirectory sourceDirectory; if (string.IsNullOrEmpty(config.AzureDirectoryCachePath)) { sourceDirectory = new AzureDirectory(storageAccount, _indexContainerName); } else { var azureDirectoryCachePath = Path.GetFullPath(Path.Combine(config.AzureDirectoryCachePath, _indexContainerName)); _logger.LogInformation("Using custom Azure Directory cache path: {AzureDirectoryCachePath}", azureDirectoryCachePath); IODirectory.CreateDirectory(azureDirectoryCachePath); var cacheDirectory = FSDirectory.Open(azureDirectoryCachePath); sourceDirectory = new AzureDirectory(storageAccount, _indexContainerName, cacheDirectory); } _directory = new RAMDirectory(sourceDirectory); // Copy the directory from Azure storage to RAM. _synchronizer = new AzureDirectorySynchronizer(sourceDirectory, _directory); stopwatch.Stop(); _logger.LogInformation($"Index reload completed and took {stopwatch.Elapsed.Seconds} seconds."); return(true); }
/// <summary> /// 获取Lucene目录 /// </summary> /// <returns></returns> public static string GetLuceneDirectory() { string luceneDirectory = null; if (LuceneDirectory.LastIndexOf(Lucene_1_Directory) > 0) { luceneDirectory = LuceneDirectory.Replace(Lucene_1_Directory, Lucene_2_Directory); } else if (LuceneDirectory.LastIndexOf(Lucene_2_Directory) > 0) { luceneDirectory = LuceneDirectory.Replace(Lucene_2_Directory, Lucene_1_Directory); } else { luceneDirectory = IOHelper.CombinePath(LuceneDirectory, Lucene_1_Directory); } Global.Logger.LogWithTime("GetLuceneDirectory()::luceneDirectory=" + luceneDirectory, Logger.ELogLevel.Trace); return(luceneDirectory); }