Update WinGet CNF for exact command matching (#19432)

## Summary of the Pull Request
Update the WinGet CNF package search to match that of the updated
PowerShell WinGet CNF module. Now, we'll only search for matching
commands instead of by name and moniker.

## References and Relevant Issues
https://github.com/microsoft/winget-command-not-found/pull/29

## Validation Steps Performed
 In CMD, type "vim" and vim packages are suggested
This commit is contained in:
Carlos Zamora 2025-10-09 14:27:41 -07:00 committed by GitHub
parent b62cad640b
commit 819987c90e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3217,33 +3217,17 @@ namespace winrt::TerminalApp::implementation
}
PackageCatalog catalog = connectResult.PackageCatalog();
// clang-format off
static constexpr std::array<WinGetSearchParams, 3> searches{ {
{ .Field = PackageMatchField::Command, .MatchOption = PackageFieldMatchOption::StartsWithCaseInsensitive },
{ .Field = PackageMatchField::Name, .MatchOption = PackageFieldMatchOption::ContainsCaseInsensitive },
{ .Field = PackageMatchField::Moniker, .MatchOption = PackageFieldMatchOption::ContainsCaseInsensitive } } };
// clang-format on
PackageMatchFilter filter = WindowsPackageManagerFactory::CreatePackageMatchFilter();
filter.Value(query);
filter.Field(PackageMatchField::Command);
filter.Option(PackageFieldMatchOption::Equals);
FindPackagesOptions options = WindowsPackageManagerFactory::CreateFindPackagesOptions();
options.Filters().Append(filter);
options.ResultLimit(20);
IVectorView<MatchResult> pkgList;
for (const auto& search : searches)
{
filter.Field(search.Field);
filter.Option(search.MatchOption);
const auto result = co_await catalog.FindPackagesAsync(options);
pkgList = result.Matches();
if (pkgList.Size() > 0)
{
break;
}
}
const auto result = co_await catalog.FindPackagesAsync(options);
const IVectorView<MatchResult> pkgList = result.Matches();
co_return pkgList;
}