#8412 In Submission Form, list collections alphabetically - solr

ordering
This commit is contained in:
Adan Roman
2022-12-16 09:38:48 +01:00
parent ffc15ec54a
commit bc6066523f
4 changed files with 20 additions and 15 deletions

View File

@@ -31,14 +31,17 @@ import org.dspace.content.DSpaceObject;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.BitstreamService; import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.DSpaceObjectService;
import org.dspace.content.service.WorkspaceItemService; import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.discovery.DiscoverQuery; import org.dspace.discovery.DiscoverQuery;
import org.dspace.discovery.DiscoverQuery.SORT_ORDER;
import org.dspace.discovery.DiscoverResult; import org.dspace.discovery.DiscoverResult;
import org.dspace.discovery.IndexableObject; import org.dspace.discovery.IndexableObject;
import org.dspace.discovery.SearchService; import org.dspace.discovery.SearchService;
import org.dspace.discovery.SearchServiceException; import org.dspace.discovery.SearchServiceException;
import org.dspace.discovery.configuration.DiscoveryConfigurationParameters.SORT;
import org.dspace.discovery.indexobject.IndexableCollection; import org.dspace.discovery.indexobject.IndexableCollection;
import org.dspace.discovery.indexobject.IndexableCommunity; import org.dspace.discovery.indexobject.IndexableCommunity;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
@@ -830,7 +833,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
query = formatCustomQuery(query); query = formatCustomQuery(query);
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" + DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
IndexableCommunity.TYPE, IndexableCommunity.TYPE,
offset, limit); offset, limit, null, null);
for (IndexableObject solrCollections : discoverResult.getIndexableObjects()) { for (IndexableObject solrCollections : discoverResult.getIndexableObjects()) {
Community community = ((IndexableCommunity) solrCollections).getIndexedObject(); Community community = ((IndexableCommunity) solrCollections).getIndexedObject();
communities.add(community); communities.add(community);
@@ -852,7 +855,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
query = formatCustomQuery(query); query = formatCustomQuery(query);
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" + DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
IndexableCommunity.TYPE, IndexableCommunity.TYPE,
null, null); null, null, null, null);
return discoverResult.getTotalSearchResults(); return discoverResult.getTotalSearchResults();
} }
@@ -877,7 +880,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
query = formatCustomQuery(query); query = formatCustomQuery(query);
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" + DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
IndexableCollection.TYPE, IndexableCollection.TYPE,
offset, limit); offset, limit,DSpaceObjectService.COMMUNITIES_AND_COLLECTIONS_SORT_FIELD,SORT_ORDER.asc);
for (IndexableObject solrCollections : discoverResult.getIndexableObjects()) { for (IndexableObject solrCollections : discoverResult.getIndexableObjects()) {
Collection collection = ((IndexableCollection) solrCollections).getIndexedObject(); Collection collection = ((IndexableCollection) solrCollections).getIndexedObject();
collections.add(collection); collections.add(collection);
@@ -899,7 +902,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
query = formatCustomQuery(query); query = formatCustomQuery(query);
DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" + DiscoverResult discoverResult = getDiscoverResult(context, query + "search.resourcetype:" +
IndexableCollection.TYPE, IndexableCollection.TYPE,
null, null); null, null, null, null);
return discoverResult.getTotalSearchResults(); return discoverResult.getTotalSearchResults();
} }
@@ -919,7 +922,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
} }
try { try {
DiscoverResult discoverResult = getDiscoverResult(context, query, null, null); DiscoverResult discoverResult = getDiscoverResult(context, query, null, null, null, null);
if (discoverResult.getTotalSearchResults() > 0) { if (discoverResult.getTotalSearchResults() > 0) {
return true; return true;
} }
@@ -931,7 +934,7 @@ public class AuthorizeServiceImpl implements AuthorizeService {
return false; 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 { throws SearchServiceException, SQLException {
String groupQuery = getGroupToQuery(groupService.allMemberGroups(context, context.getCurrentUser())); String groupQuery = getGroupToQuery(groupService.allMemberGroups(context, context.getCurrentUser()));
@@ -947,7 +950,9 @@ public class AuthorizeServiceImpl implements AuthorizeService {
if (limit != null) { if (limit != null) {
discoverQuery.setMaxResults(limit); discoverQuery.setMaxResults(limit);
} }
if (sortField != null && sortOrder != null) {
discoverQuery.setSortField(sortField, sortOrder);
}
return searchService.search(context, discoverQuery); return searchService.search(context, discoverQuery);
} }

View File

@@ -43,6 +43,7 @@ import org.dspace.core.I18nUtil;
import org.dspace.core.LogHelper; import org.dspace.core.LogHelper;
import org.dspace.core.service.LicenseService; import org.dspace.core.service.LicenseService;
import org.dspace.discovery.DiscoverQuery; import org.dspace.discovery.DiscoverQuery;
import org.dspace.discovery.DiscoverQuery.SORT_ORDER;
import org.dspace.discovery.DiscoverResult; import org.dspace.discovery.DiscoverResult;
import org.dspace.discovery.IndexableObject; import org.dspace.discovery.IndexableObject;
import org.dspace.discovery.SearchService; import org.dspace.discovery.SearchService;
@@ -946,6 +947,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE); discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE);
discoverQuery.setStart(offset); discoverQuery.setStart(offset);
discoverQuery.setMaxResults(limit); discoverQuery.setMaxResults(limit);
discoverQuery.setSortField(COMMUNITIES_AND_COLLECTIONS_SORT_FIELD, SORT_ORDER.asc);
DiscoverResult resp = retrieveCollectionsWithSubmit(context, discoverQuery, null, community, q); DiscoverResult resp = retrieveCollectionsWithSubmit(context, discoverQuery, null, community, q);
for (IndexableObject solrCollections : resp.getIndexableObjects()) { for (IndexableObject solrCollections : resp.getIndexableObjects()) {
Collection c = ((IndexableCollection) solrCollections).getIndexedObject(); Collection c = ((IndexableCollection) solrCollections).getIndexedObject();
@@ -1025,6 +1027,7 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE); discoverQuery.setDSpaceObjectFilter(IndexableCollection.TYPE);
discoverQuery.setStart(offset); discoverQuery.setStart(offset);
discoverQuery.setMaxResults(limit); discoverQuery.setMaxResults(limit);
discoverQuery.setSortField(COMMUNITIES_AND_COLLECTIONS_SORT_FIELD, SORT_ORDER.asc);
DiscoverResult resp = retrieveCollectionsWithSubmit(context, discoverQuery, DiscoverResult resp = retrieveCollectionsWithSubmit(context, discoverQuery,
entityType, community, q); entityType, community, q);
for (IndexableObject solrCollections : resp.getIndexableObjects()) { for (IndexableObject solrCollections : resp.getIndexableObjects()) {

View File

@@ -52,6 +52,10 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
= new MetadataFieldName(DC, "format"); = new MetadataFieldName(DC, "format");
public static final MetadataFieldName MD_SOURCE public static final MetadataFieldName MD_SOURCE
= new MetadataFieldName(DC, "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 * Generic find for when the precise type of an Entity is not known

View File

@@ -9,7 +9,6 @@ package org.dspace.app.rest.repository;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -46,7 +45,6 @@ import org.dspace.content.Collection;
import org.dspace.content.Community; import org.dspace.content.Community;
import org.dspace.content.EntityType; import org.dspace.content.EntityType;
import org.dspace.content.Item; import org.dspace.content.Item;
import org.dspace.content.comparator.NameAscendingComparator;
import org.dspace.content.service.BitstreamService; import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.CollectionService; import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService; import org.dspace.content.service.CommunityService;
@@ -187,7 +185,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
List<Collection> collections = cs.findCollectionsWithSubmit(q, context, com, List<Collection> collections = cs.findCollectionsWithSubmit(q, context, com,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
Collections.sort(collections, new NameAscendingComparator());
int tot = cs.countCollectionsWithSubmit(q, context, com); int tot = cs.countCollectionsWithSubmit(q, context, com);
return converter.toRestPage(collections, pageable, tot , utils.obtainProjection()); return converter.toRestPage(collections, pageable, tot , utils.obtainProjection());
} catch (SQLException | SearchServiceException e) { } catch (SQLException | SearchServiceException e) {
@@ -203,7 +200,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
List<Collection> collections = cs.findCollectionsWithSubmit(q, context, null, List<Collection> collections = cs.findCollectionsWithSubmit(q, context, null,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
Collections.sort(collections, new NameAscendingComparator());
int tot = cs.countCollectionsWithSubmit(q, context, null); int tot = cs.countCollectionsWithSubmit(q, context, null);
return converter.toRestPage(collections, pageable, tot, utils.obtainProjection()); return converter.toRestPage(collections, pageable, tot, utils.obtainProjection());
} catch (SQLException e) { } catch (SQLException e) {
@@ -220,7 +216,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
List<Collection> collections = authorizeService.findAdminAuthorizedCollection(context, query, List<Collection> collections = authorizeService.findAdminAuthorizedCollection(context, query,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
Collections.sort(collections, new NameAscendingComparator());
long tot = authorizeService.countAdminAuthorizedCollection(context, query); long tot = authorizeService.countAdminAuthorizedCollection(context, query);
return converter.toRestPage(collections, pageable, tot , utils.obtainProjection()); return converter.toRestPage(collections, pageable, tot , utils.obtainProjection());
} catch (SearchServiceException | SQLException e) { } catch (SearchServiceException | SQLException e) {
@@ -253,7 +248,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, null, entityTypeLabel, List<Collection> collections = cs.findCollectionsWithSubmit(query, context, null, entityTypeLabel,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
Collections.sort(collections, new NameAscendingComparator());
int tot = cs.countCollectionsWithSubmit(query, context, null, entityTypeLabel); int tot = cs.countCollectionsWithSubmit(query, context, null, entityTypeLabel);
return converter.toRestPage(collections, pageable, tot, utils.obtainProjection()); return converter.toRestPage(collections, pageable, tot, utils.obtainProjection());
} catch (SQLException e) { } catch (SQLException e) {
@@ -291,7 +285,6 @@ public class CollectionRestRepository extends DSpaceObjectRestRepository<Collect
List<Collection> collections = cs.findCollectionsWithSubmit(query, context, community, entityTypeLabel, List<Collection> collections = cs.findCollectionsWithSubmit(query, context, community, entityTypeLabel,
Math.toIntExact(pageable.getOffset()), Math.toIntExact(pageable.getOffset()),
Math.toIntExact(pageable.getPageSize())); Math.toIntExact(pageable.getPageSize()));
Collections.sort(collections, new NameAscendingComparator());
int total = cs.countCollectionsWithSubmit(query, context, community, entityTypeLabel); int total = cs.countCollectionsWithSubmit(query, context, community, entityTypeLabel);
return converter.toRestPage(collections, pageable, total, utils.obtainProjection()); return converter.toRestPage(collections, pageable, total, utils.obtainProjection());
} catch (SQLException | SearchServiceException e) { } catch (SQLException | SearchServiceException e) {