From 5b143b432b20d20b2efe8d37998d4e000fc8ff85 Mon Sep 17 00:00:00 2001 From: Pascal-Nicolas Becker Date: Fri, 4 Sep 2015 19:06:41 +0200 Subject: [PATCH] DS-2886: Making sort option for metadata browse indexes configurable --- .../java/org/dspace/browse/BrowseIndex.java | 48 +++++++++++++++++-- dspace/config/dspace.cfg | 8 ++-- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java b/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java index ee9e887bfd..9e6dcd8f8b 100644 --- a/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java +++ b/dspace-api/src/main/java/org/dspace/browse/BrowseIndex.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; import org.dspace.core.ConfigurationManager; import org.dspace.sort.SortOption; @@ -95,17 +96,30 @@ public final class BrowseIndex /** * Create a new BrowseIndex object using the definition from the configuration, - * and the number of the configuration option. The definition should be of - * the form: + * and the number of the configuration option. The definition should follow + * one of the following forms: * * - * [name]:[metadata]:[data type]:[display type] + * [name]:item:[sort option]:[order] + * + * + * or + * + * + * [name]:metadata:[metadata]:[data type]:[order]:[sort option] * * * [name] is a freetext name for the field + * item or metadata defines the display type * [metadata] is the usual format of the metadata such as dc.contributor.author + * [sort option] is the name of a separately defined sort option + * [order] must be either asc or desc * [data type] must be either "title", "date" or "text" - * [display type] must be either "single" or "full" + * + * If you use the first form (to define an index of type item), the order + * is facultative. If you use the second form (for type metadata), the order + * and sort option are facultative, but you must configure the order if you + * want to configure the sort option. * * @param definition the configuration definition of this index * @param number the configuration number of this index @@ -120,7 +134,7 @@ public final class BrowseIndex this.defaultOrder = SortOption.ASCENDING; this.number = number; - String rx = "(\\w+):(\\w+):([\\w\\.\\*,]+):?(\\w*):?(\\w*)"; + String rx = "(\\w+):(\\w+):([\\w\\.\\*,]+):?(\\w*):?(\\w*):?(\\w*)"; Pattern pattern = Pattern.compile(rx); Matcher matcher = pattern.matcher(definition); @@ -159,6 +173,30 @@ public final class BrowseIndex this.defaultOrder = SortOption.DESCENDING; } } + + if (matcher.groupCount() > 5) + { + String sortName = matcher.group(6).trim(); + if (sortName.length() > 0) + { + for (SortOption so : SortOption.getSortOptions()) + { + if (so.getName().equals(sortName)) + { + sortOption = so; + } + } + + // for backward compatability we ignore the keywords + // single and full here + if (!sortName.equalsIgnoreCase("single") + && !sortName.equalsIgnoreCase("full") + && sortOption == null) + { + valid = false; + } + } + } tableBaseName = getItemBrowseIndex().tableBaseName; } diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index d74a870b04..046450d77e 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -1059,7 +1059,8 @@ webui.strengths.show = false # # webui.browse.index. = : metadata : \ # .[.|.*] : \ -# (date | title | text) : (asc | desc) +# (date | title | text) : (asc | desc) : \ +# # # This form represent a unique index of metadata values from the item. # @@ -1072,9 +1073,10 @@ webui.strengths.show = false # : any other datatype will be treated the same as 'text', although # it will apply any custom ordering normalisation configured below # -# The final part of the configuration is optional, and specifies the default ordering +# The two last parts of the configuration are optional, and specifies the default ordering # for the index - whether it is ASCending (the default, and best for text indexes), or -# DESCending (useful for dates - ie. most recent submissions) +# DESCending (useful for dates - ie. most recent submissions) - and the sort option to use. +# If you want to define the sort option you must define order as well. # # NOTE: the text to render the index will use the parameter to select # the message key from Messages.properties using a key of the form: