From 831704e56c4b5d2e79e37bf65dd99e2118cece18 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Feb 2022 10:54:25 +0100 Subject: [PATCH] search: do not sort results by stars on client side Once upon a time, there was a website named ["The Docker index"][2]; a complimentary service for users of Docker, provided by dotCloud. The Docker Index was the place to find and explore pre-made container images, and allowed you to [share your images and download them][1]. The Docker Index evolved rapidly, and gained new features, such as [Trusted Images][3], and "stars" to rank your favorite images. The website also provided an API, which allowed you to search images, even from the comfort of your `docker` CLI. Things moved fast in container-land, and while there was an API to use, it was still a work in progress. While the Docker Index allowed users to "star" images, the search API did not rank results accordingly. As any engineer knows, there's no problem that can't be solved with some elbow- grease and a piece of Duct tape, so while the Docker Index team worked on making the search API better, the `docker` engine [fixed the problem on the client side][4] Years went by, and the Docker Index API became the "registry V1" specification, including search. The registry got a major "v2" rewrite and became the [OCI Distribution Spec][5], and Docker Index became Docker Hub, which included V2 and V3 search APIs. The V1 search API continued to be supported, as it was the only documented API for registries, but improvements were made, including ranking of search results. Duct tape is durable, and even though improvements were made, the Docker client continued to sort the results as well. Unfortunately, this meant that search results on the command-line were ranked different from their equivalent on the registry (such as Docker Hub). This patch removes the client-side sorting of results, using the order in which the search API returned them to (finally) celebrate the work of the engineers working on the search API, also when used from the command-line. [1]: https://web.archive.org/web/20130708004229/http://docker.io/ [2]: https://web.archive.org/web/20130623223614/https://index.docker.io/ [3]: https://web.archive.org/web/20140208001647/https://index.docker.io/ [4]: https://github.com/docker/docker/commit/1669b802cc3e7ce30f05e61630542c88696bbca1 [5]: https://github.com/opencontainers/distribution-spec Signed-off-by: Sebastiaan van Stijn --- cli/command/registry/search.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli/command/registry/search.go b/cli/command/registry/search.go index 67a051b1a5..42637ae454 100644 --- a/cli/command/registry/search.go +++ b/cli/command/registry/search.go @@ -2,7 +2,6 @@ package registry import ( "context" - "sort" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -75,9 +74,6 @@ func runSearch(dockerCli command.Cli, options searchOptions) error { return err } - sort.Slice(results, func(i, j int) bool { - return results[j].StarCount < results[i].StarCount - }) searchCtx := formatter.Context{ Output: dockerCli.Out(), Format: NewSearchFormat(options.format),