Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/app/dev/DevToys.Core/Tools/GuiToolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,21 @@ public void SearchTools(string searchQuery, ObservableCollection<GuiToolViewItem

if (weightedToolList.Count > 0)
{
var descOrderedWeightedToolList = weightedToolList.OrderByDescending(i => i.weight).ToList(); // Order by weight.
int thirdQuarterItemIndex = Math.Min((int)(0.25 * descOrderedWeightedToolList.Count), descOrderedWeightedToolList.Count - 1); // Get the 3/4 item index in the list.
double thirdQuarterWeight = descOrderedWeightedToolList[thirdQuarterItemIndex].weight; // Get the 3/4 item weight.
// Order by weight.
var descOrderedWeightedToolList
= weightedToolList.OrderByDescending(i => i.weight)
.ToList();

// Calculate the dynamic threshold.
// We will only keep the tools that have a weight of at least 45% of the max weight.
double maxWeight = descOrderedWeightedToolList.First().weight;
double threshold = maxWeight * 0.45;

searchResultListToUpdate
.AddRange(
descOrderedWeightedToolList
.Take(5) // Take the 5 first items.
.TakeWhile(i => i.weight >= thirdQuarterWeight) // Take items with a weight greater or equal to the 3/4 item weight. This is to avoid showing too many items with a low weight.
.TakeWhile(i => i.weight >= threshold)
.Select(i => i.tool));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public void ToolsMenuFavorites()
[InlineData("")]
[InlineData("BOO", "NoSearchResults")]
[InlineData("XML", "MockTool3-XMLFormatter", "MockTool4-XMLValidator")]
[InlineData("XML Validator", "MockTool4-XMLValidator")]
[InlineData("XML Valid", "MockTool4-XMLValidator")]
[InlineData("XML Validator", "MockTool4-XMLValidator", "MockTool3-XMLFormatter")]
[InlineData("XML Valid", "MockTool4-XMLValidator", "MockTool3-XMLFormatter")]
public void ToolSearch(string searchQuery, params string[] toolNames)
{
GuiToolProvider guiToolProvider = MefProvider.Import<GuiToolProvider>();
Expand Down
Loading