Skip to content

Commit

Permalink
fix: remove default sort on name of an API in the search endpoint
Browse files Browse the repository at this point in the history
When doing a search we want to rely on Lucene indexes scores to have most relevant APIs firsts in the list.

https://gravitee.atlassian.net/browse/APIM-1991
gravitee-io/issues#9095
(cherry picked from commit fbfebce)
  • Loading branch information
gaetanmaisse committed Jul 5, 2023
1 parent 8a65fed commit 9c66500
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gravitee-apim-console-webui/src/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class ApiService {
opts.params = {
q: query ? query : '*',
page: page,
order: order,
...(order ? { order: order } : {}),
size,
...(manageOnly ? {} : { manageOnly: false }),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public PagedResult<ApiListItem> searchPagedApis(
implementation = String.class,
description = "By default, sort is ASC. If *field* starts with '-', the order sort is DESC. Currently, only **name** and **paths** are supported"
)
) @QueryParam("order") @DefaultValue("name") final ApisOrderParam apisOrderParam,
) @QueryParam("order") final ApisOrderParam apisOrderParam,
@Parameter(
name = "manageOnly",
description = "By default only APIs that the user can manage are returned. If set to false, all APIs that the user can view are returned."
Expand All @@ -482,7 +482,13 @@ public PagedResult<ApiListItem> searchPagedApis(

final boolean isRatingServiceEnabled = ratingService.isEnabled(executionContext);

final Page<ApiEntity> apis = apiService.search(executionContext, query, filters, apisOrderParam.toSortable(), commonPageable);
final Page<ApiEntity> apis = apiService.search(
executionContext,
query,
filters,
apisOrderParam != null ? apisOrderParam.toSortable() : null,
commonPageable
);

return new PagedResult<>(
apis.getContent().stream().map(apiEntity -> this.convert(apiEntity, isRatingServiceEnabled)).collect(toList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.gravitee.definition.model.Proxy;
import io.gravitee.repository.exceptions.TechnicalException;
import io.gravitee.rest.api.model.api.ApiEntity;
import io.gravitee.rest.api.model.api.ApiQuery;
import io.gravitee.rest.api.model.common.Pageable;
import io.gravitee.rest.api.model.common.Sortable;
import io.gravitee.rest.api.service.common.GraviteeContext;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void get_should_search_apis() throws TechnicalException {
eq(GraviteeContext.getExecutionContext()),
eq("*"),
argThat(filters -> ((Set<String>) filters.get("api")).size() == 3),
isA(Sortable.class),
isNull(),
isA(Pageable.class)
)
)
Expand All @@ -71,6 +72,29 @@ public void get_should_search_apis() throws TechnicalException {
assertEquals(OK_200, response.getStatus());
}

@Test
public void get_should_search_apis_with_order() throws TechnicalException {
when(apiAuthorizationService.findIdsByUser(eq(GraviteeContext.getExecutionContext()), any(), isA(ApiQuery.class), eq(true)))
.thenReturn(Set.of("api1", "api2", "api15"));

List<ApiEntity> resultApis = List.of(mockApi("api1"), mockApi("api2"), mockApi("api15"));
Page<ApiEntity> apisPage = new Page<>(resultApis, 7, 3, 54);
when(
apiService.search(
eq(GraviteeContext.getExecutionContext()),
eq("*"),
argThat(filters -> ((Set<String>) filters.get("api")).size() == 3),
isA(Sortable.class),
isA(Pageable.class)
)
)
.thenReturn(apisPage);

final Response response = envTarget().path("_search/_paged").queryParam("q", "*").queryParam("order", "name").request().post(null);

assertEquals(OK_200, response.getStatus());
}

@Test
public void get_should_search_apis_with_manageOnly_to_false() throws TechnicalException {
when(apiAuthorizationService.findIdsByUser(eq(GraviteeContext.getExecutionContext()), any(), eq(false)))
Expand All @@ -84,7 +108,7 @@ public void get_should_search_apis_with_manageOnly_to_false() throws TechnicalEx
eq(GraviteeContext.getExecutionContext()),
eq("*"),
argThat(filters -> ((Set<String>) filters.get("api")).size() == 3),
isA(Sortable.class),
isNull(),
isA(Pageable.class)
)
)
Expand Down

0 comments on commit 9c66500

Please sign in to comment.