Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Jan 30, 2025
1 parent c7b81bf commit 8fca368
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/DynamoCore/Search/NodeSearchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,12 @@ internal IEnumerable<NodeSearchElement> Search(string search, LuceneSearchUtilit
/// <returns></returns>
internal NodeSearchElement FindModelForNodeNameAndCategory(string nodeName, string nodeCategory, string parameters, CancellationToken ctk = default)
{
ctk.ThrowIfCancellationRequested();

var result = Entries.Where(e => {
ctk.ThrowIfCancellationRequested();
if (e.Name.Replace(" ", string.Empty).Equals(nodeName) && e.FullCategoryName.Equals(nodeCategory))
{
ctk.ThrowIfCancellationRequested();
//When the node info was indexed if Parameters was null we added an empty space (null cannot be indexed)
//Then in this case when searching if e.Parameters is null we need to check against empty space
if (e.Parameters == null)
Expand Down
6 changes: 5 additions & 1 deletion src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class LuceneSearchUtility
internal Lucene.Net.Store.Directory indexDir;

/// <summary>
/// Lucene Index write
/// Lucene Index write. Make sure to call InitializeIndexSearcher after every index change.
/// </summary>
internal IndexWriter writer;

Expand Down Expand Up @@ -190,6 +190,10 @@ internal void CreateLuceneIndexWriter(OpenMode mode = OpenMode.CREATE)
}
}

/// <summary>
/// InitializeIndexSearcher initializes the dirReader and Searcher of this class.
/// This method should be called after every index change.
/// </summary>
private void InitializeIndexSearcher()
{
dirReader = writer != null ? writer.GetReader(applyAllDeletes: true) : DirectoryReader.Open(indexDir);
Expand Down
21 changes: 11 additions & 10 deletions src/DynamoCoreWpf/ViewModels/Search/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public bool BrowserVisibility
// Feature flags activated debouncer for the search UI.
internal ActionDebouncer searchDebouncer = null;
// Cancel token source used for the node search operations.
internal CancellationTokenSource searchCancelTooken;
internal CancellationTokenSource searchCancelToken;
// Enable running Search on a thread pool thread.
private bool enableSeachThreading;
private bool enableSearchThreading;

private string searchText = string.Empty;
/// <summary>
Expand Down Expand Up @@ -416,9 +416,9 @@ private void TryInitializeSearchFlags()
searchDebouncer ??= new ActionDebouncer(dynamoViewModel?.Model?.Logger);
}

if (DynamoModel.FeatureFlags?.CheckFeatureFlag("searchbar_spearate_thread", false) ?? false)
if (DynamoModel.FeatureFlags?.CheckFeatureFlag("searchbar_separate_thread", false) ?? false)
{
enableSeachThreading = true;
enableSearchThreading = true;
}
}

Expand Down Expand Up @@ -932,10 +932,10 @@ internal Task SearchAndUpdateResultsTask(string query)
return Task.CompletedTask;

// A new search should cancel any existing searches.
searchCancelTooken?.Cancel();
searchCancelTooken?.Dispose();
searchCancelToken?.Cancel();
searchCancelToken?.Dispose();

searchCancelTooken = new();
searchCancelToken = new();

// The TaskScheduler.FromCurrentSynchronizationContext() exists only if there is a valid SyncronizationContex/
// Calling this method from a non UI thread could have a null SyncronizationContex.Current,
Expand All @@ -945,9 +945,9 @@ internal Task SearchAndUpdateResultsTask(string query)
// We run the searches on the thread pool to reduce the impact on the UI thread.
return Task.Run(() =>
{
return Search(query, searchCancelTooken.Token);
return Search(query, searchCancelToken.Token);

}, searchCancelTooken.Token).ContinueWith((t, o) =>
}, searchCancelToken.Token).ContinueWith((t, o) =>
{
// This continuation will execute on the UI thread (forced by using FromCurrentSynchronizationContext())
searchResults = new List<NodeSearchElementViewModel>(t.Result);
Expand All @@ -965,7 +965,7 @@ internal Task SearchAndUpdateResultsTask(string query)
Please use the task based method SearchAndUpdateResultsTask instead.")]
public void SearchAndUpdateResults(string query)
{
if (enableSeachThreading)
if (enableSearchThreading)
{
SearchAndUpdateResultsTask(query);
}
Expand Down Expand Up @@ -1024,6 +1024,7 @@ private void IsSelectedChanged(object sender, PropertyChangedEventArgs e)
/// </summary>
/// <returns> Returns a list with a maximum MaxNumSearchResults elements.</returns>
/// <param name="search"> The search query </param>
/// <param name="ctk">A cancellation token for this operation.</param>
internal IEnumerable<NodeSearchElementViewModel> Search(string search, CancellationToken ctk = default)
{
if (LuceneUtility != null)
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/DynamoFeatureFlags/FeatureFlagsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal FeatureFlagsClient(string userkey, string mobileKey = null, bool testMo
//in tests we want search debouncing on so we can test it.
{ "searchbar_debounce", LdValue.Of(true) },
//in tests we want to run search on non UI thread so we can test it.
{ "searchbar_spearate_thread", LdValue.Of(true) }});
{ "searchbar_separate_thread", LdValue.Of(true) }});
return;
}

Expand Down

0 comments on commit 8fca368

Please sign in to comment.