From 6368d867da1738874aad220b90a62c928b91ed34 Mon Sep 17 00:00:00 2001 From: JT Date: Mon, 26 Jun 2023 18:20:56 -0700 Subject: [PATCH 1/2] Search Improvements: - show "No SFW results found" if you don't have NSFW mode on & there are no results - ability to search by tag & username as well as query --- StabilityMatrix/CheckpointBrowserPage.xaml | 4 +- .../ViewModels/CheckpointBrowserViewModel.cs | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/StabilityMatrix/CheckpointBrowserPage.xaml b/StabilityMatrix/CheckpointBrowserPage.xaml index 0ff791dba..3a784e6e4 100644 --- a/StabilityMatrix/CheckpointBrowserPage.xaml +++ b/StabilityMatrix/CheckpointBrowserPage.xaml @@ -139,7 +139,7 @@ AllCivitPeriods => Enum.GetValues(typeof(CivitPeriod)).Cast(); public IEnumerable AllSortModes => Enum.GetValues(typeof(CivitSortMode)).Cast(); @@ -142,7 +143,6 @@ private async Task CivitModelQuery(CivitModelsRequest request) { Logger.Debug("Cache entry already exists, not updating model cards"); } - NoResultsFound = !models.Any(); } catch (ApiException e) { @@ -153,6 +153,7 @@ private async Task CivitModelQuery(CivitModelsRequest request) finally { ShowMainLoadingSpinner = false; + UpdateResultsText(); } } @@ -164,7 +165,6 @@ private void UpdateModelCards(IEnumerable? models, CivitMetadata? me if (models is null) { ModelCards?.Clear(); - NoResultsFound = true; } else { @@ -172,7 +172,6 @@ private void UpdateModelCards(IEnumerable? models, CivitMetadata? me .Select(model => new CheckpointBrowserCardViewModel(model, downloadService, snackbarService, settingsManager)); ModelCards = new ObservableCollection(updateCards); - NoResultsFound = false; } TotalPages = metadata?.TotalPages ?? 1; CanGoToPreviousPage = CurrentPageNumber > 1; @@ -206,8 +205,20 @@ private async Task SearchModels() Sort = SortMode, Period = SelectedPeriod, Page = CurrentPageNumber, - Tag = SearchQuery }; + + if (SearchQuery.StartsWith("#")) + { + modelRequest.Tag = SearchQuery[1..]; + } + else if (SearchQuery.StartsWith("@")) + { + modelRequest.Username = SearchQuery[1..]; + } + else + { + modelRequest.Query = SearchQuery; + } if (SelectedModelType != CivitModelType.All) { @@ -220,7 +231,7 @@ private async Task SearchModels() .FindByIdAsync(ObjectHash.GetMd5Guid(modelRequest)); // If cached, update model cards - if (cachedQuery?.Items is not null && cachedQuery.Items.Any()) + if (cachedQuery is not null) { var elapsed = timer.Elapsed; Logger.Debug("Using cached query for {Text} [{RequestHash}] (in {Elapsed:F1} s)", @@ -230,14 +241,13 @@ private async Task SearchModels() // Start remote query (background mode) // Skip when last query was less than 2 min ago var timeSinceCache = DateTimeOffset.UtcNow - cachedQuery.InsertedAt; - if (timeSinceCache?.TotalMinutes < 2) + if (timeSinceCache?.TotalMinutes >= 2) { - Logger.Debug("Cached query was less than 2 minutes ago ({Seconds:F0} s), skipping remote query", + CivitModelQuery(modelRequest).SafeFireAndForget(); + Logger.Debug( + "Cached query was more than 2 minutes ago ({Seconds:F0} s), updating cache with remote query", timeSinceCache.Value.TotalSeconds); - return; } - - CivitModelQuery(modelRequest).SafeFireAndForget(); } else { @@ -245,6 +255,8 @@ private async Task SearchModels() ShowMainLoadingSpinner = true; await CivitModelQuery(modelRequest); } + + UpdateResultsText(); } [RelayCommand] @@ -282,6 +294,7 @@ partial void OnShowNsfwChanged(bool value) { settingsManager.SetModelBrowserNsfwEnabled(value); ModelCardsView?.Refresh(); + UpdateResultsText(); } partial void OnSelectedPeriodChanged(CivitPeriod oldValue, CivitPeriod newValue) @@ -312,4 +325,10 @@ private async Task TrySearchAgain(bool shouldUpdatePageNumber = true) // execute command instead of calling method directly so that the IsRunning property gets updated await SearchModelsCommand.ExecuteAsync(null); } + + private void UpdateResultsText() + { + NoResultsFound = ModelCardsView?.IsEmpty ?? true; + NoResultsText = ShowNsfw ? "No results found" : "No SFW results found"; + } } From a55e8f5977e55d749677a01af6c1a75aa3fa4bb1 Mon Sep 17 00:00:00 2001 From: JT Date: Mon, 26 Jun 2023 18:45:35 -0700 Subject: [PATCH 2/2] Show # of hidden results if any --- StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs b/StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs index 367ca07d2..92f691b3d 100644 --- a/StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs +++ b/StabilityMatrix/ViewModels/CheckpointBrowserViewModel.cs @@ -329,6 +329,8 @@ private async Task TrySearchAgain(bool shouldUpdatePageNumber = true) private void UpdateResultsText() { NoResultsFound = ModelCardsView?.IsEmpty ?? true; - NoResultsText = ShowNsfw ? "No results found" : "No SFW results found"; + NoResultsText = ModelCards?.Count == 0 + ? "No results found" + : $"{ModelCards?.Count} results hidden by filters"; } }