mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
find all top communities performance
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user