microsoft / microsoft/winget-cli
SearchForSingle versus SearchForMany leads to confusing results sometimes
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 26.4k
- Forks
- 1.8k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 15
Description
As a user, I find the difference between
SearchSourceForManyandSearchSourceForSinglequite confusing. Take a look at this for example -PS C:\WINDOWS\system32> winget search resourcehacker Name Id Version --------------------------------------------------- Resource Hacker AngusJohnson.ResourceHacker 5.1.8 PS C:\WINDOWS\system32> winget show resourcehacker No package found matching input criteria.Search clearly returned a single result, so why wouldn't show also find that single result? Is this actually a bug in
SearchSourceForSingle?_Originally posted by @Trenly in https://github.com/microsoft/winget-cli/pull/2847#discussion_r1068944891
SearchForMany searches more fields with
substringsearch, SearchForSingle on the other hand, searches only PackageName, Id, Moniker, PackageFamilyName and ProductCode withCaseInsensitivesearch, which is more strict and less likely to return multiple results.
Originally posted by @yao-msft in https://github.com/microsoft/winget-cli/pull/2847#discussion_r1068954278
Feature Request
There are times when SearchForMany will return a single package. When it does, it can make moving from a command like winget search resourcehacker (which returns a single result and uses SearchForMany) to a command like winget install resourcehacker (which returns no results and uses SearchForSingle) very frustrating for users.
Implemetation
My first thought is to start with a search for many. If search for many returns only one result, use that result. If search for many returns multiple results, then fallback to search for single. One downside to this is that if there is only 1 package returned from search for many, it has a higher likelihood of not being the package the user intended due to the additional fields being considered in search.
Second thought is to add a setting for a default query. Neutral/Unset would be the current behavior - some commands use search for single, others use search for many; Strict could be always using search for single; Broad could be always using search for many
Third thought would be to instead have an argument that could be added to make the search for single a bit less restrictive, perhaps using a substring search instead of a case insensitive search while still ignoring the additional fields considered by a search for many
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the SearchSourceForMany and SearchSourceForSingle entry points and reproduce the winget search resourcehacker and winget show resourcehacker behavior. Compare their matching rules and review the three proposed approaches; the work is done when one behavior is selected, implemented, and covered by tests for single-result and multiple-result searches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, search
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100