Skip to content

Commit

Permalink
(GH-1033) List/Search on Tags Only
Browse files Browse the repository at this point in the history
Previously, a search filter would take many parts of the package information
into account. When wanting to perform a search based on tags only, this
proved to be a bit more difficult. Implement a tag-based search vew a new
`--by-tags-only` argument to limit results based on the tags.
  • Loading branch information
Russell Mora authored and ferventcoder committed May 18, 2017
1 parent a75e0fc commit 2d80e6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("by-id-only",
"ByIdOnly - Only return packages where the id contains the search filter. Available in 0.9.10+.",
option => configuration.ListCommand.ByIdOnly = option != null)
.Add("by-tag-only|by-tags-only",
"ByTagOnly - Only return packages where the search filter matches on the tags. Available in 0.10.6+.",
option => configuration.ListCommand.ByTagOnly = option != null)
.Add("id-starts-with",
"IdStartsWith - Only return packages where the id starts with the search filter. Available in 0.9.10+.",
option => configuration.ListCommand.IdStartsWith = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ public ListCommandConfiguration()
public int PageSize { get; set; }
public bool Exact { get; set; }
public bool ByIdOnly { get; set; }
public bool ByTagOnly { get; set; }
public bool IdStartsWith { get; set; }
public bool OrderByPopularity { get; set; }
public bool ApprovedOnly { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ private static IQueryable<IPackage> execute_package_search(ChocolateyConfigurati
: results.Where(p => p.Id.contains(searchTermLower, StringComparison.OrdinalIgnoreCase));
}

if (configuration.ListCommand.ByTagOnly)
{
results = isRemote
? results.Where(p => p.Tags.Contains(searchTermLower))
: results.Where(p => p.Tags.contains(searchTermLower, StringComparison.InvariantCultureIgnoreCase));
}

if (configuration.ListCommand.IdStartsWith)
{
results = isRemote ?
Expand Down

0 comments on commit 2d80e6c

Please sign in to comment.