Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved search accuracy #1423

Merged
merged 1 commit into from
Oct 21, 2024
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