Skip to content

Commit

Permalink
(NuGet#9) New order by for version searching by version
Browse files Browse the repository at this point in the history
When searching by version number in the 1.x version of Chocolatey, an
additional orderby of "Id, Version desc" is included.  In order to
maintain backwards compatibility, we need to also include this orderby
in the new NuGet.Client based implementation.

This work is similar to the work that was done in this commit, where
the DownloadCount orderby was added:

chocolatey@d28424e

This commit adds the Version property to SearchOrderBy, which can then
be used within chocolatey/choco codebase, when required.
  • Loading branch information
gep13 committed Feb 24, 2023
1 parent 5af6acb commit 3bca820
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class V2FeedQueryBuilder
//////////////////////////////////////////////////////////

private const string DownloadCountProperty = "DownloadCount";
private const string VersionProperty = "Version";

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
Expand Down Expand Up @@ -306,6 +307,10 @@ private string BuildOrderBy(SearchOrderBy? searchOrderBy)
orderBy = string.Format("{0}%20desc,{1}", DownloadCountProperty, IdProperty);
break;

case SearchOrderBy.Version:
orderBy = string.Format("{0},{1}%20desc", IdProperty, VersionProperty);
break;

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public async Task<bool> MoveNextAsync()
// Local packages do not have downloads available
goto default;

case SearchOrderBy.Version:
_currentEnumerator = results.OrderBy(p => p.Identity.Id).ThenByDescending(p => p.Identity.Version).GetEnumerator();
break;

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetada
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.VersionDownloadCount.get -> int?
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.VersionDownloadCount.set -> void
NuGet.Protocol.Core.Types.SearchOrderBy.DownloadCount = 1 -> NuGet.Protocol.Core.Types.SearchOrderBy
NuGet.Protocol.Core.Types.SearchOrderBy.Version = 2 -> NuGet.Protocol.Core.Types.SearchOrderBy
NuGet.Protocol.HttpSourceResource.OverrideHttpSource(NuGet.Protocol.IHttpSource source) -> void
NuGet.Protocol.IHttpSource
NuGet.Protocol.IHttpSource.GetAsync<T>(NuGet.Protocol.HttpSourceCachedRequest request, System.Func<NuGet.Protocol.HttpSourceResult, System.Threading.Tasks.Task<T>> processAsync, NuGet.Common.ILogger log, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetada
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.VersionDownloadCount.get -> int?
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.VersionDownloadCount.set -> void
NuGet.Protocol.Core.Types.SearchOrderBy.DownloadCount = 1 -> NuGet.Protocol.Core.Types.SearchOrderBy
NuGet.Protocol.Core.Types.SearchOrderBy.Version = 2 -> NuGet.Protocol.Core.Types.SearchOrderBy
NuGet.Protocol.HttpSourceResource.OverrideHttpSource(NuGet.Protocol.IHttpSource source) -> void
NuGet.Protocol.IHttpSource
NuGet.Protocol.IHttpSource.GetAsync<T>(NuGet.Protocol.HttpSourceCachedRequest request, System.Func<NuGet.Protocol.HttpSourceResult, System.Threading.Tasks.Task<T>> processAsync, NuGet.Common.ILogger log, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task<T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetada
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.VersionDownloadCount.get -> int?
NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.VersionDownloadCount.set -> void
NuGet.Protocol.Core.Types.SearchOrderBy.DownloadCount = 1 -> NuGet.Protocol.Core.Types.SearchOrderBy
NuGet.Protocol.Core.Types.SearchOrderBy.Version = 2 -> NuGet.Protocol.Core.Types.SearchOrderBy
NuGet.Protocol.HttpSourceResource.OverrideHttpSource(NuGet.Protocol.IHttpSource source) -> void
NuGet.Protocol.IHttpSource
NuGet.Protocol.IHttpSource.GetAsync<T>(NuGet.Protocol.HttpSourceCachedRequest request, System.Func<NuGet.Protocol.HttpSourceResult, System.Threading.Tasks.Task<T>> processAsync, NuGet.Common.ILogger log, System.Threading.CancellationToken token) -> System.Threading.Tasks.Task<T>
Expand Down
7 changes: 6 additions & 1 deletion src/NuGet.Core/NuGet.Protocol/SearchOrderBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ public enum SearchOrderBy
/// <summary>
/// Order the resulting packages by number of donwnloads.
/// </summary>
DownloadCount
DownloadCount,

/// <summary>
/// Order the resulting packages grouped by the version number
/// </summary>
Version

//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
Expand Down

0 comments on commit 3bca820

Please sign in to comment.