Skip to content

Commit

Permalink
Merge pull request #6958 from QualitativeDataRepository/IQSS/4977
Browse files Browse the repository at this point in the history
Iqss/4977 - Reorder Publication Year Facet Chronologically
  • Loading branch information
kcondon committed Jun 22, 2020
2 parents 4ee469f + e25e2aa commit b97185a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/release-notes/4977-facet-sort-setting
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
New setting for Dataverse Admins:

The new :ChronologicalDateFacets setting. Default to true.

Facets with Date/Year are sorted chronologically by default, with the most recent value first. To have them sorted by number of hits, e.g. with the year with the most results first, set this to false
9 changes: 9 additions & 0 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2108,3 +2108,12 @@ Allows Cross-Origin Resource sharing(CORS). By default this setting is absent an
If you don’t want to allow CORS for your installation, set:

``curl -X PUT -d 'false' http://localhost:8080/api/admin/settings/:AllowCors``

:ChronologicalDateFacets
++++++++++++++++++++++++

Unlike other facets, those indexed by Date/Year are sorted chronologically by default, with the most recent value first. To have them sorted by number of hits, e.g. with the year with the most results first, set this to false

If you don’t want date facets to be sorted chronologically, set:

``curl -X PUT -d 'false' http://localhost:8080/api/admin/settings/:ChronologicalDateFacets``
6 changes: 6 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ public boolean isMakeDataCountDisplayEnabled() {
return isTrueForKey(SettingsServiceBean.Key.DisplayMDCMetrics, safeDefaultIfKeyNotFound);

}

public boolean displayChronologicalDateFacets() {
//Defaults to true
return isTrueForKey(SettingsServiceBean.Key.ChronologicalDateFacets, true);

}

}

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 @@ -5,9 +5,12 @@
import edu.harvard.iq.dataverse.DataFileTag;
import edu.harvard.iq.dataverse.DataTable;
import edu.harvard.iq.dataverse.Dataset;
import edu.harvard.iq.dataverse.DatasetFieldType;
import edu.harvard.iq.dataverse.DatasetFieldType.FieldType;
import edu.harvard.iq.dataverse.DatasetServiceBean;
import edu.harvard.iq.dataverse.DatasetVersionServiceBean;
import edu.harvard.iq.dataverse.Dataverse;
import edu.harvard.iq.dataverse.DataverseFacet;
import edu.harvard.iq.dataverse.DataversePage;
import edu.harvard.iq.dataverse.DataverseServiceBean;
import edu.harvard.iq.dataverse.DataverseSession;
Expand All @@ -33,6 +36,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 +454,30 @@ public void search(boolean onlyDataRelatedToMe) {

setDisplayCardValues();

if (settingsWrapper.displayChronologicalDateFacets()) {
Set<String> facetsToSort = new HashSet<String>();
facetsToSort.add(SearchFields.PUBLICATION_YEAR);
List<DataverseFacet> facets = dataversePage.getDataverse().getDataverseFacets();
for (DataverseFacet facet : facets) {
DatasetFieldType dft = facet.getDatasetFieldType();
if (dft.getFieldType() == FieldType.DATE) {
// Currently all date fields are stored in solr as strings and so get an "_s" appended.
// If these someday are indexed as dates, this should change
facetsToSort.add(dft.getName()+"_s");
}
}

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



dataversePage.setQuery(query);
dataversePage.setFacetCategoryList(facetCategoryList);
dataversePage.setFilterQueries(filterQueriesFinal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,12 @@ Whether Harvesting (OAI) service is enabled
/**
* Validate physical files for all the datafiles in the dataset when publishing
*/
FileValidationOnPublishEnabled
FileValidationOnPublishEnabled,
/**
* Sort Date Facets Chronologically instead or presenting them in order of # of hits as other facets are. Default is true
*/
ChronologicalDateFacets

;

@Override
Expand Down

0 comments on commit b97185a

Please sign in to comment.