Skip to content

Commit

Permalink
(GH-663) Search Order By Popularity
Browse files Browse the repository at this point in the history
Allow ordering search results by popularity. This aids in filtering
search results with tab completion.
  • Loading branch information
ferventcoder committed Mar 23, 2016
1 parent 8a689bf commit b7e5ff9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("id-starts-with",
"IdStartsWith - Only return packages where the id starts with the search filter.",
option => configuration.ListCommand.IdStartsWith = option != null)
.Add("order-by-popularity",
"OrderByPopularity - Sort by package results by popularity.",
option => configuration.ListCommand.OrderByPopularity = option != null)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ public ListCommandConfiguration()
public bool Exact { get; set; }
public bool ByIdOnly { get; set; }
public bool IdStartsWith { get; set; }
public bool OrderByPopularity { get; set; }
}

[Serializable]
Expand Down
6 changes: 5 additions & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ private static IQueryable<IPackage> execute_package_search(ChocolateyConfigurati
.AsQueryable();
}

return results.OrderBy(p => p.Id);
results = configuration.ListCommand.OrderByPopularity ?
results.OrderByDescending(p => p.DownloadCount).ThenBy(p => p.Id)
: results.OrderBy(p => p.Id) ;

return results;
}


Expand Down

0 comments on commit b7e5ff9

Please sign in to comment.