mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 04:53:16 +00:00
#8412 In Submission Form, list collections alphabetically - solr
ordering
This commit is contained in:
@@ -31,14 +31,17 @@ import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.content.service.WorkspaceItemService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.DiscoverQuery;
|
||||
import org.dspace.discovery.DiscoverQuery.SORT_ORDER;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.discovery.SearchService;
|
||||
import org.dspace.discovery.SearchServiceException;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfigurationParameters.SORT;
|
||||
import org.dspace.discovery.indexobject.IndexableCollection;
|
||||
import org.dspace.discovery.indexobject.IndexableCommunity;
|
||||
import org.dspace.eperson.EPerson;
|
||||
@@ -830,7 +833,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
query = formatCustomQuery(query);
|
||||
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
|
||||
IndexableCommunity.TYPE,
|
||||
offset, limit);
|
||||
offset, limit, null, null);
|
||||
for (IndexableObject solrCollections : discoverResult.getIndexableObjects()) {
|
||||
Community community = ((IndexableCommunity) solrCollections).getIndexedObject();
|
||||
communities.add(community);
|
||||
@@ -852,7 +855,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
query = formatCustomQuery(query);
|
||||
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
|
||||
IndexableCommunity.TYPE,
|
||||
null, null);
|
||||
null, null, null, null);
|
||||
return discoverResult.getTotalSearchResults();
|
||||
}
|
||||
|
||||
@@ -877,7 +880,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
query = formatCustomQuery(query);
|
||||
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
|
||||
IndexableCollection.TYPE,
|
||||
offset, limit);
|
||||
offset, limit,DSpaceObjectService.COMMUNITIES_AND_COLLECTIONS_SORT_FIELD,SORT_ORDER.asc);
|
||||
for (IndexableObject solrCollections : discoverResult.getIndexableObjects()) {
|
||||
Collection collection = ((IndexableCollection) solrCollections).getIndexedObject();
|
||||
collections.add(collection);
|
||||
@@ -899,7 +902,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
query = formatCustomQuery(query);
|
||||
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
|
||||
IndexableCollection.TYPE,
|
||||
null, null);
|
||||
null, null, null, null);
|
||||
return discoverResult.getTotalSearchResults();
|
||||
}
|
||||
|
||||
@@ -919,7 +922,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
}
|
||||
|
||||
try {
|
||||
DiscoverResult discoverResult = getDiscoverResult(context, query, null, null);
|
||||
DiscoverResult discoverResult = getDiscoverResult(context, query, null, null, null, null);
|
||||
if (discoverResult.getTotalSearchResults() > 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -931,7 +934,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private DiscoverResult getDiscoverResult(Context context, String query, Integer offset, Integer limit)
|
||||
private DiscoverResult getDiscoverResult(Context context, String query, Integer offset, Integer limit, String sortField, SORT_ORDER sortOrder)
|
||||
throws SearchServiceException, SQLException {
|
||||
String groupQuery = getGroupToQuery(groupService.allMemberGroups(context, context.getCurrentUser()));
|
||||
|
||||
@@ -947,7 +950,9 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
||||
if (limit != null) {
|
||||
discoverQuery.setMaxResults(limit);
|
||||
}
|
||||
|
||||
if (sortField != null && sortOrder != null) {
|
||||
discoverQuery.setSortField(sortField, sortOrder);
|
||||
}
|
||||
|
||||
return searchService.search(context, discoverQuery);
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ import org.dspace.core.I18nUtil;
|
||||
import org.dspace.core.LogHelper;
|
||||
import org.dspace.core.service.LicenseService;
|
||||
import org.dspace.discovery.DiscoverQuery;
|
||||
import org.dspace.discovery.DiscoverQuery.SORT_ORDER;
|
||||
import org.dspace.discovery.DiscoverResult;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.discovery.SearchService;
|
||||
@@ -946,6 +947,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE);
|
||||
discoverQuery.setStart(offset);
|
||||
discoverQuery.setMaxResults(limit);
|
||||
discoverQuery.setSortField(COMMUNITIES_AND_COLLECTIONS_SORT_FIELD, SORT_ORDER.asc);
|
||||
DiscoverResult resp = retrieveCollectionsWithSubmit(context, discoverQuery, null, community, q);
|
||||
for (IndexableObject solrCollections : resp.getIndexableObjects()) {
|
||||
Collection c = ((IndexableCollection) solrCollections).getIndexedObject();
|
||||
@@ -1025,6 +1027,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE);
|
||||
discoverQuery.setStart(offset);
|
||||
discoverQuery.setMaxResults(limit);
|
||||
discoverQuery.setSortField(COMMUNITIES_AND_COLLECTIONS_SORT_FIELD, SORT_ORDER.asc);
|
||||
DiscoverResult resp = retrieveCollectionsWithSubmit(context, discoverQuery,
|
||||
entityType, community, q);
|
||||
for (IndexableObject solrCollections : resp.getIndexableObjects()) {
|
||||
|
@@ -52,6 +52,10 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
|
||||
= new MetadataFieldName(DC, "format");
|
||||
public static final MetadataFieldName MD_SOURCE
|
||||
= new MetadataFieldName(DC, "source");
|
||||
/*
|
||||
* Field used to sort community and collection lists at solr
|
||||
*/
|
||||
public static final String COMMUNITIES_AND_COLLECTIONS_SORT_FIELD = "dc.title_sort";
|
||||
|
||||
/**
|
||||
* Generic find for when the precise type of an Entity is not known
|
||||
|
@@ -9,7 +9,6 @@ package org.dspace.app.rest.repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -46,7 +45,6 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.EntityType;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.comparator.NameAscendingComparator;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
@@ -187,7 +185,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
||||
List<Collection> collections = cs.findCollectionsWithSubmit(q, context, com,
|
||||
Math.toIntExact(pageable.getOffset()),
|
||||
Math.toIntExact(pageable.getPageSize()));
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
int tot = cs.countCollectionsWithSubmit(q, context, com);
|
||||
return converter.toRestPage(collections, pageable, tot , utils.obtainProjection());
|
||||
} catch (SQLException | SearchServiceException e) {
|
||||
@@ -203,7 +200,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
||||
List<Collection> collections = cs.findCollectionsWithSubmit(q, context, null,
|
||||
Math.toIntExact(pageable.getOffset()),
|
||||
Math.toIntExact(pageable.getPageSize()));
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
int tot = cs.countCollectionsWithSubmit(q, context, null);
|
||||
return converter.toRestPage(collections, pageable, tot, utils.obtainProjection());
|
||||
} catch (SQLException e) {
|
||||
@@ -220,7 +216,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
||||
List<Collection> collections = authorizeService.findAdminAuthorizedCollection(context, query,
|
||||
Math.toIntExact(pageable.getOffset()),
|
||||
Math.toIntExact(pageable.getPageSize()));
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
long tot = authorizeService.countAdminAuthorizedCollection(context, query);
|
||||
return converter.toRestPage(collections, pageable, tot , utils.obtainProjection());
|
||||
} catch (SearchServiceException | SQLException e) {
|
||||
@@ -253,7 +248,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
||||
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, null, entityTypeLabel,
|
||||
Math.toIntExact(pageable.getOffset()),
|
||||
Math.toIntExact(pageable.getPageSize()));
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
int tot = cs.countCollectionsWithSubmit(query, context, null, entityTypeLabel);
|
||||
return converter.toRestPage(collections, pageable, tot, utils.obtainProjection());
|
||||
} catch (SQLException e) {
|
||||
@@ -291,7 +285,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
|
||||
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, community, entityTypeLabel,
|
||||
Math.toIntExact(pageable.getOffset()),
|
||||
Math.toIntExact(pageable.getPageSize()));
|
||||
Collections.sort(collections, new NameAscendingComparator());
|
||||
int total = cs.countCollectionsWithSubmit(query, context, community, entityTypeLabel);
|
||||
return converter.toRestPage(collections, pageable, total, utils.obtainProjection());
|
||||
} catch (SQLException | SearchServiceException e) {
|
||||
|
Reference in New Issue
Block a user