Skip to content

Commit

Permalink
#436 get facet information for list view only when required
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Collins committed Feb 21, 2025
1 parent c37c6fe commit 09f8700
Show file tree
Hide file tree
Showing 22 changed files with 375 additions and 225 deletions.
428 changes: 288 additions & 140 deletions grails-app/assets/javascripts/search.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions grails-app/assets/stylesheets/search.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
Document : search
Created on : Feb 10, 2011, 4:23:15 PM
Author : "Nick dos Remedios <[email protected]>"
Expand All @@ -9,7 +9,7 @@
*= require_self
*/

/*
/*
TODO customize this sample style
Syntax recommendation http://www.w3.org/TR/REC-CSS2/
*/
Expand Down Expand Up @@ -356,7 +356,7 @@ span.activeFq, span.facet-item {
vertical-align: top;
display: inline-block;
width: 90%;
margin-left: -4px;
/*margin-left: -4px;*/
text-indent: 0px;
/*font-weight: bold;*/
}
Expand Down Expand Up @@ -845,6 +845,8 @@ ul.facets {
padding-left:0;
margin-left:0;
list-style:none;
overflow-y: scroll;
max-height: 91px;
}

ul.facets li {
Expand Down
9 changes: 9 additions & 0 deletions grails-app/conf/ehcache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@
<heap unit="entries">100000</heap>
</resources>
</cache>

<cache alias="qualityShortTermCache">
<expiry>
<ttl unit="hours">1</ttl>
</expiry>
<resources>
<heap unit="entries">10000</heap>
</resources>
</cache>
</config>
1 change: 0 additions & 1 deletion grails-app/conf/plugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ exploreYourArea.lng = "149.0"
exploreYourArea.location = "Canberra, ACT"
exploreYourArea.zoomLevels = [ 1: 14, 5: 12, 10: 11, 50: 9 ]

facets.includeDynamicFacets = false // sandbox
facets.limit = "100"
facets.max = "40"
facets.customOrder = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,10 @@ class OccurrenceController {
}
}

// List dynamicFacets = []

String[] requestedFacets = userFacets ?: filteredFacets

// if (grailsApplication.config.getProperty('facets.includeDynamicFacets', Boolean, false)) {
// // Sandbox only...
// time("sandbox only facets") {
// dynamicFacets = webServicesService.getDynamicFacets(requestParams.q)
// requestedFacets = postProcessingService.mergeRequestedFacets(requestedFacets as List, dynamicFacets)
// }
// }

requestParams.facets = requestedFacets
// Disable the biocache-service request for facets. They are new retrieved dynamically by the client
requestParams.facets = null

def wsStart = System.currentTimeMillis()
JSONObject searchResults = time("full text search") { webServicesService.fullTextSearch(requestParams) }
Expand All @@ -125,10 +116,13 @@ class OccurrenceController {
}

//create a facet lookup map
Map groupedFacetsMap = postProcessingService.getMapOfFacetResults(searchResults.facetResults)
Map groupedFacetsMap = postProcessingService.getMapOfFacetResults(requestedFacets)

//grouped facets
Map groupedFacets = postProcessingService.getAllGroupedFacets(configuredGroupedFacets, searchResults.facetResults, [])
Map groupedFacets = postProcessingService.getAllGroupedFacets(configuredGroupedFacets, groupedFacetsMap)

//grouped facets, but only those requested and not in the activeFacetMap
Map groupedFacetsRequested = postProcessingService.getRequestedGroupedFacets(configuredGroupedFacets, groupedFacetsMap, requestedFacets, searchResults?.activeFacetMap)

//remove qc from active facet map
if (params?.qc) {
Expand Down Expand Up @@ -183,8 +177,8 @@ class OccurrenceController {
searchRequestParams : requestParams,
defaultFacets : defaultFacets,
groupedFacets : groupedFacets,
groupedFacetsRequested: groupedFacetsRequested,
groupedFacetsMap : groupedFacetsMap,
dynamicFacets : [],
selectedDataResource: getSelectedResource(requestParams.q),
hasImages : hasImages,
showSpeciesImages : false,
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_ca.properties
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ map.downloadmap.button01.label=Descarregar mapa
map.downloadmap.button02.label=Tanca

facets.currentfilter.link=Esborrar totes
facets.groupdynamicfacets.link=seleccioneu m\u00e9s
facets.facetfromgroup.link=seleccioneu m\u00e9s
facets.multiplefacets.title=Filtrar la cerca
facets.multiplefacets.tableth01=Comptatge
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ map.downloadmap.button01.label=Karte herunterladen
map.downloadmap.button02.label=Schlie\u00dfen

facets.currentfilter.link=Alles l\u00f6schen
facets.groupdynamicfacets.link=weitere ausw\u00e4hlen
facets.facetfromgroup.link=weitere ausw\u00e4hlen
facets.multiplefacets.title=Suche einschr\u00e4nken
facets.multiplefacets.tableth01=Anzahl
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_de_AT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ map.downloadmap.button01.label=Karte herunterladen
map.downloadmap.button02.label=Schlie\u00dfen

facets.currentfilter.link=Alles l\u00f6schen
facets.groupdynamicfacets.link=weitere ausw\u00e4hlen
facets.facetfromgroup.link=weitere ausw\u00e4hlen
facets.multiplefacets.title=Suche einschr\u00e4nken
facets.multiplefacets.tableth01=Anzahl
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_de_LU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ map.downloadmap.button01.label=Karte herunterladen
map.downloadmap.button02.label=Schlie\u00dfen

facets.currentfilter.link=Alles l\u00f6schen
facets.groupdynamicfacets.link=weitere ausw\u00e4hlen
facets.facetfromgroup.link=weitere ausw\u00e4hlen
facets.multiplefacets.title=Suche einschr\u00e4nken
facets.multiplefacets.tableth01=Anzahl
Expand Down
2 changes: 1 addition & 1 deletion grails-app/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ map.downloadmap.button01.label = Download map
map.downloadmap.button02.label = Close

facets.currentfilter.link = Clear all
facets.groupdynamicfacets.link = choose more

facets.facetfromgroup.link = choose more
facets.multiplefacets.title = Refine your search
facets.multiplefacets.tableth01 = Count
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ map.downloadmap.button01.label=Descargar mapa
map.downloadmap.button02.label=Cerrar

facets.currentfilter.link=Borrar todo
facets.groupdynamicfacets.link=elegir m\u00e1s
facets.facetfromgroup.link=elegir m\u00e1s
facets.multiplefacets.title=Filtrar la b\u00fasqueda
facets.multiplefacets.tableth01=Recuento
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_eu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ map.downloadmap.button01.label=Jeitsi mapa
map.downloadmap.button02.label=Itxi

facets.currentfilter.link=Ezabatu dena
facets.groupdynamicfacets.link=Aukeratu gehiago
facets.facetfromgroup.link=Aukeratu gehiago
facets.multiplefacets.title=Zehaztu zure bilaketa
facets.multiplefacets.tableth01=Kopurua
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ map.downloadmap.button02.label=Fermer
map.legend.click.to.expand = Afficher la l\u00e9gende

facets.currentfilter.link=Tout effacer
facets.groupdynamicfacets.link=choisir plus de
facets.facetfromgroup.link=choisir plus de
facets.multiplefacets.title=Affiner votre recherche
facets.multiplefacets.tableth01=Total
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ map.downloadmap.button01.label=Baixar mapa
map.downloadmap.button02.label=Fechar

facets.currentfilter.link=Limpar tudo
facets.groupdynamicfacets.link=escolha mais
facets.facetfromgroup.link=escolha mais
facets.multiplefacets.title=Refine a sua pesquisa
facets.multiplefacets.tableth01=Contagem
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_pt_PT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ map.downloadmap.button01.label=Transferir mapa
map.downloadmap.button02.label=Fechar

facets.currentfilter.link=Limpar tudo
facets.groupdynamicfacets.link=escolha mais
facets.facetfromgroup.link=escolha mais
facets.multiplefacets.title=Refine a sua pesquisa
facets.multiplefacets.tableth01=Contagem
Expand Down
1 change: 0 additions & 1 deletion grails-app/i18n/messages_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ map.downloadmap.button01.label=\u4e0b\u8f7d\u5730\u56fe
map.downloadmap.button02.label=\u5173\u95ed

facets.currentfilter.link=\u6e05\u9664\u6240\u6709
facets.groupdynamicfacets.link=\u9009\u62e9\u66f4\u591a
facets.facetfromgroup.link=\u9009\u62e9\u66f4\u591a
facets.multiplefacets.title=\u4f18\u5316\u4f60\u7684\u67e5\u8be2
facets.multiplefacets.tableth01=\u8ba1\u6570
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class PostProcessingService {
* @param finalFacetsMap
* @return
*/
def String[] getFilteredFacets(LinkedHashMap<String, Boolean> finalFacetsMap) {
String[] getFilteredFacets(LinkedHashMap<String, Boolean> finalFacetsMap) {
List finalFacets = []

for (String key : finalFacetsMap.keySet()) {
Expand All @@ -188,7 +188,6 @@ class PostProcessingService {
}
}

//log.debug("FinalFacets = " + StringUtils.join(finalFacets, "|"));
String[] filteredFacets = finalFacets.toArray(new String[finalFacets.size()]);

return filteredFacets
Expand Down Expand Up @@ -326,17 +325,17 @@ class PostProcessingService {
* @param facetResults
* @return
*/
def Map getMapOfFacetResults(JSONArray facetResults) {
Map getMapOfFacetResults(String[] requestedFacets) {
Map facetMap = [:]

facetResults.each { fr ->
def facet = fr.fieldName
requestedFacets.each { fn ->
def facet = fn

if (facet == "occurrence_year") {
facet = "decade"
}

facetMap.put(facet, fr)
facetMap.put(facet, [fieldName: fn]) // data for this key will be populated by the client
}

facetMap
Expand All @@ -350,21 +349,49 @@ class PostProcessingService {
* @param ungroupedFacetsList
* @return
*/
def Map getAllGroupedFacets(Map groupedFacets, def facetResults, dynamicFacets) {
List ungroupedFacetsList = getUngroupedFacetsList(groupedFacets, getMapOfFacetResults(facetResults))
Map getAllGroupedFacets(Map groupedFacets, Map groupedFacetsMap) {
List ungroupedFacetsList = getUngroupedFacetsList(groupedFacets, groupedFacetsMap)
def finalGroupedFacets = groupedFacets.clone()
def dynamicFacetNames = dynamicFacets.collect { it.name }
finalGroupedFacets.put("Ungrouped", [])
ungroupedFacetsList.each { facet ->
if (dynamicFacetNames.contains(facet)) {
finalGroupedFacets.get("Custom").add(facet)
} else {
finalGroupedFacets.get("Ungrouped").add(facet)
}
finalGroupedFacets.get("Ungrouped").add(facet)
}
finalGroupedFacets
}

/**
* Add only the requested ungrouped facets from search results to the groupedFacetsMap
* used to construct the facets column in search results.
*
* @param groupedFacets
* @param ungroupedFacetsList
* @return
*/
Map getRequestedGroupedFacets(Map groupedFacets, Map groupedFacetsMap, String[] requestedFacets, Map activeFacetMap) {
List ungroupedFacetsList = getUngroupedFacetsList(groupedFacets, groupedFacetsMap)
def finalGroupedFacets = groupedFacets.clone()
finalGroupedFacets.put("Ungrouped", [])
ungroupedFacetsList.each { facet ->
finalGroupedFacets.get("Ungrouped").add(facet)
}

def requestedFacetsSet = requestedFacets.sort() as Set
def requestedGroupedFacets = [:]
finalGroupedFacets.each { key, list ->
def requestedList = []
for (String item : list) {
if (requestedFacetsSet.contains(item) && !activeFacetMap.containsKey(item)) {
requestedList.add(item)
}
}
if (requestedList.size() > 0) {
requestedGroupedFacets.put(key, requestedList)
}
}

requestedGroupedFacets
}

/**
* Get a list of facet fields (from search results) that are
* NOT in the grouped facets Map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class QualityService {

}

@Cacheable(value = 'qualityShortTermCache', key = { profileName })
List<QualityCategory> findAllEnabledCategories(String profileName) {
if (dataQualityEnabled) {
return responseOrThrow(api.findAllEnabledCategories(profileName))
Expand All @@ -95,6 +96,7 @@ class QualityService {
}
}

@Cacheable(value = 'qualityShortTermCache', key = { profileName })
QualityProfile activeProfile(String profileName) {
if (dataQualityEnabled) {
return responseOrThrow(api.activeProfile(profileName))
Expand All @@ -119,6 +121,7 @@ class QualityService {
}
}

@Cacheable(value = 'qualityShortTermCache', key = { profile.name })
Map<String, String> getAllInverseCategoryFiltersForProfile(QualityProfile profile) {
if (dataQualityEnabled) {
return responseOrThrow(api.getAllInverseCategoryFiltersForProfile(profile.id?.toInteger()))
Expand All @@ -127,6 +130,7 @@ class QualityService {
}
}

@Cacheable(value = 'qualityShortTermCache', key = { enabled })
List<QualityProfile> findAllEnabledProfiles(boolean enabled) {
if (dataQualityEnabled) {
return responseOrThrow(dataProfilesApi.dataProfiles(null, null, null, null, enabled, null, null))
Expand Down Expand Up @@ -162,7 +166,7 @@ class QualityService {

private Long countRecordsExcludedByLabel(List<String> otherLabels, SpatialSearchRequestParams requestParams) {
def srp = requestParams.clone().with {
it.pageSize = 0
it.pageSize = 1 // when it is 0 it will return 20 records
it.start = 0
it.flimit = 0
it.facet = false
Expand All @@ -178,7 +182,7 @@ class QualityService {
Long countTotalRecords(SpatialSearchRequestParams requestParams) {
if (dataQualityEnabled) {
def srp = requestParams.clone().with {
it.pageSize = 0
it.pageSize = 1 // when it is 0 it will return 20 records
it.start = 0
it.flimit = 0
it.facet = false
Expand All @@ -205,7 +209,7 @@ class QualityService {
def otherLabels = (labels - it.label) as List
[(it.label): totalRecords - countRecordsExcludedByLabel(otherLabels, requestParams)]
}
log.error("Quality Category facet counts took {}", sw)
log.debug("Quality Category facet counts took {}", sw)
return response
} else {
return [:]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,24 +428,6 @@ class WebServicesService {
imageSizes
}

/**
* Get list of dynamic facets for a given query (Sandbox)
*
* @param query
* @return
*/
// List getDynamicFacets(String query) {
// def url = "${grailsApplication.config.getProperty('biocache.baseUrl')}/upload/dynamicFacets?q=${query}"
// JSONArray facets = getJsonElements(url)
// def dfs = []
// facets.each {
// if (it.name && it.displayName) {
// dfs.add([name: it.name, displayName: it.displayName])
// } // reduce to List of Maps
// }
// dfs
// }

/**
* Use HTTP HEAD to determine the file size of a URL (image)
*
Expand Down
Loading

0 comments on commit 09f8700

Please sign in to comment.