From a9199f9c746b1ae03c4941cd6a114746d459a9b7 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 3 Jun 2020 15:24:23 -0400 Subject: [PATCH 01/12] try sorting pub year facet --- .../iq/dataverse/search/SearchIncludeFragment.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index ab301d304c3..d4d2ff3dcb2 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -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; @@ -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()==SearchFields.PUBLICATION_YEAR) { + Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); + } + } + + dataversePage.setQuery(query); dataversePage.setFacetCategoryList(facetCategoryList); dataversePage.setFilterQueries(filterQueriesFinal); From 825376baa8fa1208f3536a1166d1f665b779f38a Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 3 Jun 2020 15:49:31 -0400 Subject: [PATCH 02/12] debug - log facet names --- .../edu/harvard/iq/dataverse/search/SearchIncludeFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index d4d2ff3dcb2..6603ab696a9 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -453,6 +453,7 @@ public void search(boolean onlyDataRelatedToMe) { //Sort Pub Year Chronologically (alphabetically descending - works until 10000 AD) for(FacetCategory fc: facetCategoryList) { + logger.info("Found facet: " + fc.getName()); if(fc.getName()==SearchFields.PUBLICATION_YEAR) { Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); } From 42ec4fd3ae9db25120ffddd0cda8dd716368b991 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 3 Jun 2020 16:01:26 -0400 Subject: [PATCH 03/12] implement comparable for FacetLabel --- .../java/edu/harvard/iq/dataverse/search/FacetLabel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java b/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java index bebd6b418fc..ac3d9ec7e99 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java @@ -3,7 +3,7 @@ import javax.inject.Named; @Named -public class FacetLabel { +public class FacetLabel implements Comparable{ private String name; private Long count; @@ -46,4 +46,9 @@ public void setFilterQuery(String filterQuery) { this.filterQuery = filterQuery; } + @Override + public int compareTo(FacetLabel otherFacetLabel) { + return name.compareTo(otherFacetLabel.getName()); + } + } From 8ee16c8dd3024895780d535dcbfcc20ebaab07bb Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 3 Jun 2020 16:14:16 -0400 Subject: [PATCH 04/12] debug - print ordering --- src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java | 4 ++++ .../harvard/iq/dataverse/search/SearchIncludeFragment.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java b/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java index ac3d9ec7e99..cc23177a8b1 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java @@ -50,5 +50,9 @@ public void setFilterQuery(String filterQuery) { public int compareTo(FacetLabel otherFacetLabel) { return name.compareTo(otherFacetLabel.getName()); } + + public String toString() { + return getName() + "(" + getCount() + ")"; + } } diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index 6603ab696a9..112181c8b2c 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -455,7 +455,9 @@ public void search(boolean onlyDataRelatedToMe) { for(FacetCategory fc: facetCategoryList) { logger.info("Found facet: " + fc.getName()); if(fc.getName()==SearchFields.PUBLICATION_YEAR) { - Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); + logger.info("Before: " + fc.getFacetLabel().toString()); + Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); + logger.info("After: " + fc.getFacetLabel().toString()); } } From 82f359eef1a80bcf8dc82778fba3480d3760dfbe Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 3 Jun 2020 16:36:21 -0400 Subject: [PATCH 05/12] use Java equals() :-) --- .../edu/harvard/iq/dataverse/search/SearchIncludeFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index 112181c8b2c..61cbb98463f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -454,7 +454,7 @@ public void search(boolean onlyDataRelatedToMe) { //Sort Pub Year Chronologically (alphabetically descending - works until 10000 AD) for(FacetCategory fc: facetCategoryList) { logger.info("Found facet: " + fc.getName()); - if(fc.getName()==SearchFields.PUBLICATION_YEAR) { + if(fc.getName().equals(SearchFields.PUBLICATION_YEAR)) { logger.info("Before: " + fc.getFacetLabel().toString()); Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); logger.info("After: " + fc.getFacetLabel().toString()); From 5aec8a02bc5fec75fde7db584bfc099b272c075b Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 3 Jun 2020 16:51:46 -0400 Subject: [PATCH 06/12] remove debug logging, add comments --- .../java/edu/harvard/iq/dataverse/search/FacetLabel.java | 7 +++---- .../harvard/iq/dataverse/search/SearchIncludeFragment.java | 3 --- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java b/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java index cc23177a8b1..f8bd0ea5a10 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/FacetLabel.java @@ -48,11 +48,10 @@ public void setFilterQuery(String 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()); } - - public String toString() { - return getName() + "(" + getCount() + ")"; - } } diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index 61cbb98463f..18f64bdab86 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -453,11 +453,8 @@ public void search(boolean onlyDataRelatedToMe) { //Sort Pub Year Chronologically (alphabetically descending - works until 10000 AD) for(FacetCategory fc: facetCategoryList) { - logger.info("Found facet: " + fc.getName()); if(fc.getName().equals(SearchFields.PUBLICATION_YEAR)) { - logger.info("Before: " + fc.getFacetLabel().toString()); Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); - logger.info("After: " + fc.getFacetLabel().toString()); } } From db2f38d45599132157b5268d2ede86542742bbe1 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Fri, 12 Jun 2020 17:14:30 -0400 Subject: [PATCH 07/12] sort all date facets by default, make configurable --- .../harvard/iq/dataverse/SettingsWrapper.java | 6 +++++ .../search/SearchIncludeFragment.java | 25 ++++++++++++++++--- .../settings/SettingsServiceBean.java | 7 +++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java b/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java index 665291f7797..a9f9d298a9f 100644 --- a/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java +++ b/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java @@ -265,6 +265,12 @@ public boolean isMakeDataCountDisplayEnabled() { return isTrueForKey(SettingsServiceBean.Key.DisplayMDCMetrics, safeDefaultIfKeyNotFound); } + + public boolean sortDateFacets() { + //Defaults to true + return isTrueForKey(SettingsServiceBean.Key.SortDateFacets, true); + + } } diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index 18f64bdab86..ead389fde64 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -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; @@ -451,13 +454,27 @@ 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()); + if (settingsWrapper.sortDateFacets()) { + Set facetsToSort = new HashSet(); + facetsToSort.add(SearchFields.PUBLICATION_YEAR); + List facets = dataversePage.getDataverse().getDataverseFacets(); + for (DataverseFacet facet : facets) { + DatasetFieldType dft = facet.getDatasetFieldType(); + if (dft.getFieldType() == FieldType.DATE) { + facetsToSort.add(dft.getName()); + } + } + + // 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); diff --git a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java index be83b28fd45..1a586ff6a40 100644 --- a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java @@ -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 + */ + SortDateFacets + ; @Override From 1149e854d5f2ec4ed54201d4781b08d9ecb0b83b Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Fri, 12 Jun 2020 17:28:37 -0400 Subject: [PATCH 08/12] debugging --- .../edu/harvard/iq/dataverse/search/SearchIncludeFragment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index ead389fde64..1cb6ad47fd8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -462,12 +462,14 @@ public void search(boolean onlyDataRelatedToMe) { DatasetFieldType dft = facet.getDatasetFieldType(); if (dft.getFieldType() == FieldType.DATE) { facetsToSort.add(dft.getName()); + logger.info("Adding facet to sort: " + dft.getName()); } } // Sort Pub Year Chronologically (alphabetically descending - works until 10000 // AD) for (FacetCategory fc : facetCategoryList) { + logger.info("Found facet: " + fc.getName()); if (facetsToSort.contains(fc.getName())) { Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); } From d617f73b77d08b2bf27cb06b2c008e83373cb8ff Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Fri, 12 Jun 2020 17:47:14 -0400 Subject: [PATCH 09/12] include _s and remove debug --- .../harvard/iq/dataverse/search/SearchIncludeFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index 1cb6ad47fd8..1679627abfd 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -461,15 +461,15 @@ public void search(boolean onlyDataRelatedToMe) { for (DataverseFacet facet : facets) { DatasetFieldType dft = facet.getDatasetFieldType(); if (dft.getFieldType() == FieldType.DATE) { - facetsToSort.add(dft.getName()); - logger.info("Adding facet to sort: " + dft.getName()); + // 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) { - logger.info("Found facet: " + fc.getName()); if (facetsToSort.contains(fc.getName())) { Collections.sort(fc.getFacetLabel(), Collections.reverseOrder()); } From f032d61d39f0791c917a46dcec8be964edfe57c6 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Fri, 12 Jun 2020 18:05:11 -0400 Subject: [PATCH 10/12] doc and update setting name --- doc/sphinx-guides/source/installation/config.rst | 9 +++++++++ .../java/edu/harvard/iq/dataverse/SettingsWrapper.java | 4 ++-- .../iq/dataverse/search/SearchIncludeFragment.java | 2 +- .../iq/dataverse/settings/SettingsServiceBean.java | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/sphinx-guides/source/installation/config.rst b/doc/sphinx-guides/source/installation/config.rst index 06c251a1a76..789935573da 100644 --- a/doc/sphinx-guides/source/installation/config.rst +++ b/doc/sphinx-guides/source/installation/config.rst @@ -2049,3 +2049,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`` diff --git a/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java b/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java index a9f9d298a9f..556c2294bda 100644 --- a/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java +++ b/src/main/java/edu/harvard/iq/dataverse/SettingsWrapper.java @@ -266,9 +266,9 @@ public boolean isMakeDataCountDisplayEnabled() { } - public boolean sortDateFacets() { + public boolean displayChronologicalDateFacets() { //Defaults to true - return isTrueForKey(SettingsServiceBean.Key.SortDateFacets, true); + return isTrueForKey(SettingsServiceBean.Key.ChronologicalDateFacets, true); } diff --git a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java index 1679627abfd..52556f00d53 100644 --- a/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java +++ b/src/main/java/edu/harvard/iq/dataverse/search/SearchIncludeFragment.java @@ -454,7 +454,7 @@ public void search(boolean onlyDataRelatedToMe) { setDisplayCardValues(); - if (settingsWrapper.sortDateFacets()) { + if (settingsWrapper.displayChronologicalDateFacets()) { Set facetsToSort = new HashSet(); facetsToSort.add(SearchFields.PUBLICATION_YEAR); List facets = dataversePage.getDataverse().getDataverseFacets(); diff --git a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java index 1a586ff6a40..4b69f016a46 100644 --- a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java @@ -434,7 +434,7 @@ Whether Harvesting (OAI) service is enabled /** * Sort Date Facets Chronologically instead or presenting them in order of # of hits as other facets are. Default is true */ - SortDateFacets + ChronologicalDateFacets ; From ae3b5f27bf0302ade510e1e6e2f0b3613a05763f Mon Sep 17 00:00:00 2001 From: Danny Brooke Date: Sat, 13 Jun 2020 13:41:46 -0400 Subject: [PATCH 11/12] adding release note --- doc/release-notes/4977-facet-sort-setting | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/release-notes/4977-facet-sort-setting diff --git a/doc/release-notes/4977-facet-sort-setting b/doc/release-notes/4977-facet-sort-setting new file mode 100644 index 00000000000..c957c8c4510 --- /dev/null +++ b/doc/release-notes/4977-facet-sort-setting @@ -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 \ No newline at end of file From e25e2aa91e6cbcab64ee73794f21bd8f06ba812f Mon Sep 17 00:00:00 2001 From: qqmyers Date: Thu, 18 Jun 2020 09:54:37 -0400 Subject: [PATCH 12/12] fix formatting --- doc/sphinx-guides/source/installation/config.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sphinx-guides/source/installation/config.rst b/doc/sphinx-guides/source/installation/config.rst index 789935573da..07a5e3c358f 100644 --- a/doc/sphinx-guides/source/installation/config.rst +++ b/doc/sphinx-guides/source/installation/config.rst @@ -2051,7 +2051,7 @@ 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