File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed
dspace-api/src/main/java/org/dspace/sort Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change 77 */
88package org .dspace .sort ;
99
10+ import java .util .Date ;
11+
12+ import org .dspace .util .MultiFormatDateParser ;
13+
1014/**
11- * Standard date ordering delegate implementation. The only "special" need is
12- * to treat dates with less than 4-digit year .
15+ * Standard date ordering delegate implementation using date format
16+ * parsing from o.d.u.MultiFormatDateParser .
1317 *
1418 * @author Andrea Bollini
19+ * @author Alan Orth
1520 */
1621public class OrderFormatDate implements OrderFormatDelegate {
1722 @ Override
1823 public String makeSortString (String value , String language ) {
19- int padding = 0 ;
20- int endYearIdx = value .indexOf ('-' );
21-
22- if (endYearIdx >= 0 && endYearIdx < 4 ) {
23- padding = 4 - endYearIdx ;
24- } else if (value .length () < 4 ) {
25- padding = 4 - value .length ();
26- }
24+ Date result = MultiFormatDateParser .parse (value );
2725
28- if (padding > 0 ) {
29- // padding the value from left with 0 so that 87 -> 0087, 687-11-24
30- // -> 0687-11-24
31- return String .format ("%1$0" + padding + "d" , 0 )
32- + value ;
26+ // If parsing was successful we return the value as an ISO instant,
27+ // otherwise we return null so Solr does not index this date value.
28+ if (result != null ) {
29+ return result .toInstant ().toString ();
3330 } else {
34- return value ;
31+ return null ;
3532 }
3633 }
3734}
You can’t perform that action at this time.
0 commit comments