use of io.gravitee.repository.management.api.search.ApiCriteria in project gravitee-management-rest-api by gravitee-io.
the class ApiServiceImpl method search.
@Override
public Page<ApiEntity> search(String query, Map<String, Object> filters, Sortable sortable, Pageable pageable) {
try {
LOGGER.debug("Search paged APIs by {}", query);
Query<ApiEntity> apiQuery = QueryBuilder.create(ApiEntity.class).setQuery(query).setFilters(filters).build();
SearchResult matchApis = searchEngineService.search(apiQuery);
if (matchApis.getDocuments().isEmpty()) {
return new Page<>(emptyList(), 0, 0, 0);
}
final ApiCriteria apiCriteria = new ApiCriteria.Builder().ids(matchApis.getDocuments().toArray(new String[0])).build();
final Page<Api> apiPage = sortAndPaginate(apiRepository.search(apiCriteria), sortable, pageable);
// merge all apis
final List<ApiEntity> apis = convert(apiPage.getContent());
return new Page<>(apis, apiPage.getPageNumber(), (int) apiPage.getPageElements(), apiPage.getTotalElements());
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to search paged apis", ex);
throw new TechnicalManagementException("An error occurs while trying to search paged apis", ex);
}
}
Aggregations