Código fonte Wiki de SolrFileSizeFacet
Última modificação por Admin Admin em 16/08/2018, 09:36
Show last authors
| 1 | {{velocity output="false"}} |
| 2 | #macro (displaySearchFacetValues_fileSize $facetValues) |
| 3 | ## |
| 4 | ## Predefined size intervals, specified in bytes. |
| 5 | ## |
| 6 | #set ($intervals = $solrConfig.facet.fileSize.intervals) |
| 7 | #foreach ($interval in $intervals) |
| 8 | #set ($start = $interval.start) |
| 9 | #set ($end = $interval.end) |
| 10 | #if (!$start) |
| 11 | #set ($start = '*') |
| 12 | #set ($hint = $services.localization.render('solr.facet.size.lessThan', ["#dynamicsize($end)"])) |
| 13 | #elseif (!$end) |
| 14 | #set ($end = '*') |
| 15 | #set ($hint = $services.localization.render('solr.facet.size.moreThan', ["#dynamicsize($start)"])) |
| 16 | #else |
| 17 | #set ($hint = $services.localization.render('solr.facet.size.between', ["#dynamicsize($start)", "#dynamicsize($end)"])) |
| 18 | #end |
| 19 | #set ($discard = $interval.putAll({ |
| 20 | 'label': $services.localization.render("solr.facet.size.$interval.id"), |
| 21 | 'hint': $hint, |
| 22 | 'name': "[$start TO $end]", |
| 23 | 'count': 0 |
| 24 | })) |
| 25 | #end |
| 26 | ## |
| 27 | ## Add custom size intervals specified on the request. |
| 28 | ## |
| 29 | #foreach ($selectedValue in $facetRequestValues) |
| 30 | ## Determine if the value/range is custom. |
| 31 | #set ($custom = true) |
| 32 | #foreach ($interval in $intervals) |
| 33 | #if ($interval.name == $selectedValue) |
| 34 | #set ($custom = false) |
| 35 | #break |
| 36 | #end |
| 37 | #end |
| 38 | #if ($custom) |
| 39 | #set ($rangeMatcher = $rangePattern.matcher($selectedValue)) |
| 40 | #if ($rangeMatcher.matches()) |
| 41 | #set ($discard = $intervals.add({ |
| 42 | 'start': $mathtool.toInteger($rangeMatcher.group(1)), |
| 43 | 'end' : $mathtool.toInteger($rangeMatcher.group(2)), |
| 44 | 'name' : $selectedValue, |
| 45 | 'count': 0 |
| 46 | })) |
| 47 | #end |
| 48 | #end |
| 49 | #end |
| 50 | ## |
| 51 | ## Count matches for each date interval. |
| 52 | ## |
| 53 | #foreach ($facetValue in $facetValues) |
| 54 | #set ($size = $mathtool.toInteger($facetValue.name)) |
| 55 | #foreach ($interval in $intervals) |
| 56 | #if ((!$interval.start || $interval.start <= $size) |
| 57 | && (!$interval.end || $size < $interval.end)) |
| 58 | #set ($discard = $interval.put('count', $mathtool.add($interval.count, $facetValue.count))) |
| 59 | #end |
| 60 | #end |
| 61 | #end |
| 62 | ## Filter the size intervals that don't have matches. |
| 63 | #set ($intervalsWithMatches = []) |
| 64 | #foreach ($interval in $intervals) |
| 65 | #if ($interval.count > 0 || $facetRequestValues.contains($interval.name)) |
| 66 | #set ($discard = $intervalsWithMatches.add($interval)) |
| 67 | #end |
| 68 | #end |
| 69 | ## Make sure we sort the intervals based on the number of matches. |
| 70 | #set ($intervals = $sorttool.sort($intervalsWithMatches, 'count:desc')) |
| 71 | ## |
| 72 | ## Display the size intervals. |
| 73 | ## |
| 74 | <ul> |
| 75 | #foreach ($facetValue in $intervals) |
| 76 | <li>#displaySearchFacetValue($facetValue {} 'displaySearchFacetValue_fileSize')</li> |
| 77 | #end |
| 78 | </ul> |
| 79 | #end |
| 80 | |
| 81 | #macro (displaySearchFacetValue_fileSize $sizeInterval) |
| 82 | #if ($facetValue.label) |
| 83 | <span title="$escapetool.xml($facetValue.hint)">$escapetool.xml($facetValue.label)</span> |
| 84 | #elseif ($facetValue.start || $facetValue.end) |
| 85 | ## Display the custom interval. |
| 86 | #if (!$facetValue.start) |
| 87 | $escapetool.xml($services.localization.render('solr.facet.size.lessThan', |
| 88 | ["#dynamicsize($facetValue.end)"])) |
| 89 | #elseif (!$facetValue.end) |
| 90 | $escapetool.xml($services.localization.render('solr.facet.size.moreThan', |
| 91 | ["#dynamicsize($facetValue.start)"])) |
| 92 | #else |
| 93 | $services.localization.render('solr.facet.size.between', |
| 94 | ["#dynamicsize($facetValue.start)", "#dynamicsize($facetValue.end)"]) |
| 95 | #end |
| 96 | #else |
| 97 | $escapetool.xml($services.localization.render('solr.facet.size.any')) |
| 98 | #end |
| 99 | #end |
| 100 | {{/velocity}} |
| 101 | |
| 102 | {{velocity}} |
| 103 | #if ($facetValues) |
| 104 | {{html clean="false"}}#displaySearchFacetValues_fileSize($facetValues){{/html}} |
| 105 | #end |
| 106 | {{/velocity}} |