Skip to content

Commit

Permalink
Improved search accuracy (#1423)
Browse files Browse the repository at this point in the history
  • Loading branch information
veler authored Oct 21, 2024
1 parent 3db6ee2 commit d50a877
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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

0 comments on commit d50a877

Please sign in to comment.