From ce96bc16f3f094b2363b72308b90d60afe7ccd24 Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" Date: Fri, 6 Oct 2023 03:14:31 -0400 Subject: [PATCH] Update --- src/DynamoCore/Models/DynamoModel.cs | 4 +-- .../Utilities/LuceneSearchUtility.cs | 31 ++++++++++++++----- .../PackageManagerSearchViewModel.cs | 3 +- .../Search/NodeAutoCompleteSearchViewModel.cs | 1 - 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs index e973f8d98d4..a0022bb8542 100644 --- a/src/DynamoCore/Models/DynamoModel.cs +++ b/src/DynamoCore/Models/DynamoModel.cs @@ -921,9 +921,7 @@ protected DynamoModel(IStartConfiguration config) CustomNodeManager = new CustomNodeManager(NodeFactory, MigrationManager, LibraryServices); - LuceneSearch.LuceneUtilityNodeSearch = new LuceneSearchUtility(new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.NodesIndexingDirectory)); - - LuceneUtility.InitializeLuceneConfig(); + LuceneSearch.LuceneUtilityNodeSearch = new LuceneSearchUtility(LuceneSearchUtility.DefaultNodeIndexStartConfig); InitializeCustomNodeManager(); diff --git a/src/DynamoCore/Utilities/LuceneSearchUtility.cs b/src/DynamoCore/Utilities/LuceneSearchUtility.cs index 9ca9526c15c..5b7ecab05d4 100644 --- a/src/DynamoCore/Utilities/LuceneSearchUtility.cs +++ b/src/DynamoCore/Utilities/LuceneSearchUtility.cs @@ -63,7 +63,17 @@ internal class LuceneSearchUtility /// /// Default start config for Lucene, it will use RAM storage type and empty directory /// - internal static LuceneStartConfig DefaultStartConfig = new LuceneStartConfig(); + internal static readonly LuceneStartConfig DefaultStartConfig = new LuceneStartConfig(); + + /// + /// Start config for node index, it will use file storage type and node index directory + /// + internal static readonly LuceneStartConfig DefaultNodeIndexStartConfig = new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.NodesIndexingDirectory); + + /// + /// Start config for package index, it will use file storage type and package index directory + /// + internal static readonly LuceneStartConfig DefaultPkgIndexStartConfig = new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.PackagesIndexingDirectory); public enum LuceneStorage { @@ -88,10 +98,11 @@ internal LuceneSearchUtility(LuceneStartConfig config) { // If under test mode, use the default StartConfig - RAM storage type and empty directory startConfig = DynamoModel.IsTestMode? DefaultStartConfig : config; + InitializeLuceneConfig(); } /// - /// Initialize Lucene config file writer. + /// Initialize Lucene index writer based on start config. /// internal void InitializeLuceneConfig() { @@ -111,9 +122,15 @@ internal void InitializeLuceneConfig() indexDir = FSDirectory.Open(indexPath); } - - // Create an analyzer to process the text - Analyzer = CreateAnalyzerByLanguage(PreferenceSettings.Instance.Locale); + try + { + // Create an analyzer to process the text + Analyzer = CreateAnalyzerByLanguage(PreferenceSettings.Instance.Locale); + } + catch (Exception) + { + Analyzer = new LuceneCustomAnalyzer(LuceneConfig.LuceneNetVersion); + } // Check if Lucene index file exists, if not create it // TODO: Add a check to see if the index is corrupted and recreate it if it is @@ -456,12 +473,12 @@ protected override TokenStreamComponents CreateComponents(string fieldName, Text internal class LuceneStartConfig { /// - /// Lucene Index Directory name, e.g. Nodes + /// Lucene Index Directory name, e.g. Nodes, Packages /// internal string Directory { get; set; } /// - /// Current Lucene Index Storage type, it could be RAM or FILE_SYSTEM + /// Current Lucene Index Storage type, it could be either RAM or FILE_SYSTEM /// internal LuceneSearchUtility.LuceneStorage StorageType { get; set; } diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs index 10b8d0bd180..26d3ef7385f 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs @@ -621,9 +621,8 @@ internal void InitializeLuceneForPackageManager() { if(LuceneUtility == null) { - LuceneSearch.LuceneUtilityPackageManager = new LuceneSearchUtility(new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.PackagesIndexingDirectory)); + LuceneSearch.LuceneUtilityPackageManager = new LuceneSearchUtility(LuceneSearchUtility.DefaultPkgIndexStartConfig); } - LuceneUtility.InitializeLuceneConfig(); } /// diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs index 72d69c08f0c..684a2895c33 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs @@ -683,7 +683,6 @@ internal void SearchAutoCompleteCandidates(string input) else { LuceneSearch.LuceneUtilityNodeAutocomplete = new LuceneSearchUtility(LuceneSearchUtility.DefaultStartConfig); - LuceneUtility.InitializeLuceneConfig(); //Memory indexing process for Node Autocomplete (indexing just the nodes returned by the NodeAutocomplete service so we limit the scope of the query search) foreach (var node in searchElementsCache.Select(x => x.Model))