From 7dc2a05c45e6be92c02f284870c4b2a8159427ae Mon Sep 17 00:00:00 2001 From: Corey Hayward <72159232+CoreyHayward@users.noreply.github.com> Date: Fri, 25 Apr 2025 05:27:54 +0100 Subject: [PATCH] [PTRun] Allow preventing usage based ordering results (#37491) * Allow preventing selected result data retrieval * Updated implementation to calculate sort order on result and update property name to better reflect purpose * Update Result.cs sort order method name Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Align with the name GetSortOrderScore --------- Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> Co-authored-by: Gordon Lam (SH) --- .../PowerLauncher/ViewModel/ResultsViewModel.cs | 4 ++-- src/modules/launcher/Wox.Plugin/Result.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs index 02e6138b30..64a52e8385 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/ResultsViewModel.cs @@ -282,11 +282,11 @@ namespace PowerLauncher.ViewModel if (options.SearchQueryTuningEnabled) { - sorted = Results.OrderByDescending(x => (x.Result.Metadata.WeightBoost + x.Result.Score + (x.Result.SelectedCount * options.SearchClickedItemWeight))).ToList(); + sorted = Results.OrderByDescending(x => x.Result.GetSortOrderScore(options.SearchClickedItemWeight)).ToList(); } else { - sorted = Results.OrderByDescending(x => (x.Result.Metadata.WeightBoost + x.Result.Score + (x.Result.SelectedCount * 5))).ToList(); + sorted = Results.OrderByDescending(x => x.Result.GetSortOrderScore(5)).ToList(); } // remove history items in they are in the list as non-history items diff --git a/src/modules/launcher/Wox.Plugin/Result.cs b/src/modules/launcher/Wox.Plugin/Result.cs index 91f026bbb2..3bbb6dbf5e 100644 --- a/src/modules/launcher/Wox.Plugin/Result.cs +++ b/src/modules/launcher/Wox.Plugin/Result.cs @@ -187,5 +187,20 @@ namespace Wox.Plugin /// Gets plugin ID that generated this result /// public string PluginID { get; internal set; } + + /// + /// Gets or sets a value indicating whether usage based sorting should be applied to this result. + /// + public bool DisableUsageBasedScoring { get; set; } + + public int GetSortOrderScore(int selectedItemMultiplier) + { + if (DisableUsageBasedScoring) + { + return Metadata.WeightBoost + Score; + } + + return Metadata.WeightBoost + Score + (SelectedCount * selectedItemMultiplier); + } } }