Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iqss/4977 - Reorder Publication Year Facet Chronologically #6958

Merged
merged 13 commits into from
Jun 22, 2020
10 changes: 9 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javax.inject.Named;

@Named
public class FacetLabel {
public class FacetLabel implements Comparable<FacetLabel>{

private String name;
private Long count;
Expand Down Expand Up @@ -46,4 +46,12 @@ public void setFilterQuery(String filterQuery) {
this.filterQuery = filterQuery;
}

@Override
public int compareTo(FacetLabel otherFacetLabel) {
// This is used to 'chronologically' order entries in the Publication Year facet
// display. That should work for 4 digit years (until 10K AD), but this could be
// changed to do a real numberical comparison instead.
return name.compareTo(otherFacetLabel.getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -450,6 +451,14 @@ public void search(boolean onlyDataRelatedToMe) {

setDisplayCardValues();

//Sort Pub Year Chronologically (alphabetically descending - works until 10000 AD)
for(FacetCategory fc: facetCategoryList) {
if(fc.getName().equals(SearchFields.PUBLICATION_YEAR)) {
Collections.sort(fc.getFacetLabel(), Collections.reverseOrder());
}
}


dataversePage.setQuery(query);
dataversePage.setFacetCategoryList(facetCategoryList);
dataversePage.setFilterQueries(filterQueriesFinal);
Expand Down