find all top communities performance

This commit is contained in:
Ben Bosman
2021-10-14 10:40:00 +02:00
parent d9d24427af
commit 47a97b2b21

View File

@@ -192,14 +192,26 @@ public class CommunityRestRepository extends DSpaceObjectRestRepository<Communit
}
}
// TODO: Add methods in dspace api to support pagination of top level
// communities
@SearchRestMethod(name = "top")
public Page<CommunityRest> findAllTop(Pageable pageable) {
try {
List<Community> communities = cs.findAllTop(obtainContext());
return converter.toRestPage(communities, pageable, utils.obtainProjection());
} catch (SQLException e) {
Context context = obtainContext();
List<Community> topLevelCommunities = new LinkedList<Community>();
DiscoverQuery discoverQuery = new DiscoverQuery();
discoverQuery.setQuery("*:*");
discoverQuery.setDSpaceObjectFilter(IndexableCommunity.TYPE);
discoverQuery.addFilterQueries("-location.parent:*");
discoverQuery.setStart(Math.toIntExact(pageable.getOffset()));
discoverQuery.setSortField("dc.title_sort", DiscoverQuery.SORT_ORDER.asc);
discoverQuery.setMaxResults(pageable.getPageSize());
DiscoverResult resp = searchService.search(context, discoverQuery);
long tot = resp.getTotalSearchResults();
for (IndexableObject solrCommunities : resp.getIndexableObjects()) {
Community c = ((IndexableCommunity) solrCommunities).getIndexedObject();
topLevelCommunities.add(c);
}
return converter.toRestPage(topLevelCommunities, pageable, tot, utils.obtainProjection());
} catch (SearchServiceException e) {
throw new RuntimeException(e.getMessage(), e);
}
}