Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
QilongTang committed Oct 6, 2023
1 parent 3ed0099 commit ce96bc1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
31 changes: 24 additions & 7 deletions src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ internal class LuceneSearchUtility
/// <summary>
/// Default start config for Lucene, it will use RAM storage type and empty directory
/// </summary>
internal static LuceneStartConfig DefaultStartConfig = new LuceneStartConfig();
internal static readonly LuceneStartConfig DefaultStartConfig = new LuceneStartConfig();

/// <summary>
/// Start config for node index, it will use file storage type and node index directory
/// </summary>
internal static readonly LuceneStartConfig DefaultNodeIndexStartConfig = new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.NodesIndexingDirectory);

/// <summary>
/// Start config for package index, it will use file storage type and package index directory
/// </summary>
internal static readonly LuceneStartConfig DefaultPkgIndexStartConfig = new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.PackagesIndexingDirectory);

public enum LuceneStorage
{
Expand All @@ -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();
}

/// <summary>
/// Initialize Lucene config file writer.
/// Initialize Lucene index writer based on start config.
/// </summary>
internal void InitializeLuceneConfig()
{
Expand All @@ -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
Expand Down Expand Up @@ -456,12 +473,12 @@ protected override TokenStreamComponents CreateComponents(string fieldName, Text
internal class LuceneStartConfig
{
/// <summary>
/// Lucene Index Directory name, e.g. Nodes
/// Lucene Index Directory name, e.g. Nodes, Packages
/// </summary>
internal string Directory { get; set; }

/// <summary>
/// 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
/// </summary>
internal LuceneSearchUtility.LuceneStorage StorageType { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ce96bc1

Please sign in to comment.