Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-68534] Sort first, then limit #6569

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,6 @@ public HttpResponse doPluginsSearch(@QueryParameter String query, @QueryParamete
.anyMatch(category -> StringUtils.containsIgnoreCase(category, query)) ||
plugin.hasWarnings() && query.equalsIgnoreCase("warning:");
})
.limit(Math.max(limit - plugins.size(), 1))
.sorted((o1, o2) -> {
String o1DisplayName = o1.getDisplayName();
if (o1.name.equalsIgnoreCase(query) ||
Expand All @@ -1424,6 +1423,7 @@ public HttpResponse doPluginsSearch(@QueryParameter String query, @QueryParamete
}
return o1DisplayName.compareTo(o2DisplayName);
})
.limit(Math.max(limit - plugins.size(), 1))
.map(plugin -> {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", plugin.name);
Expand Down
22 changes: 22 additions & 0 deletions test/src/test/java/hudson/PluginManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,28 @@ public void doNotThrowWithUnknownPlugins() throws Exception {
uc.getPluginsWithUnavailableUpdates();
}

@Test
public void searchCommonTermFirstHitIsExactName() throws Exception {
Jenkins.get().getPluginManager().doCheckUpdatesServer();
JenkinsRule.JSONWebResponse response = r.getJSON("pluginManager/pluginsSearch?query=repo&limit=50");
JSONObject json = response.getJSONObject();
assertTrue(json.has("data"));
JSONArray data = json.getJSONArray("data");
assertEquals("repo plugin should be first hit", "repo", data.getJSONObject(0).get("name"));
assertEquals("50 results matching limit", 50, data.size());
}

@Test
public void r() throws Exception {
Jenkins.get().getPluginManager().doCheckUpdatesServer();
JenkinsRule.JSONWebResponse response = r.getJSON("pluginManager/pluginsSearch?query=r&limit=50");
JSONObject json = response.getJSONObject();
assertTrue(json.has("data"));
JSONArray data = json.getJSONArray("data");
assertEquals("r plugin should be first hit", "r", data.getJSONObject(0).get("name"));
assertEquals("50 results matching limit", 50, data.size());
}

@Test @Issue("JENKINS-64840")
public void searchMultipleUpdateSites() throws Exception {
assumeFalse("TODO: Implement this test for Windows", Functions.isWindows());
Expand Down