Afficher les derniers auteurs
1 {{velocity output="false"}}
2 #set ($defaultDateFormat = 'yyyy/MM/dd HH:mm')
3 #set ($iso8601DateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'")
4
5 #macro (displaySearchFacetValues_date $facetValues)
6 #set ($discard = $xwiki.ssx.use('Main.SolrDateFacet'))
7 #set ($discard = $xwiki.jsx.use('Main.SolrDateFacet'))
8 ##
9 ## Build the list of date intervals.
10 ##
11 ## 1. Predefined date intervals.
12 ## We use the start of the day as point of reference instead of the current precise date & time in order for the date
13 ## facet to be properly cached (during that day). Otherwise, if we use NOW in a filter range query then a new cache
14 ## entry is generated for each search request because NOW is expanded to the actual date & time in the filter query.
15 ## See http://searchhub.org/2012/02/23/date-math-now-and-filter-queries/ for details.
16 #set ($startOfToday = $xwiki.jodatime.dateTime.withTimeAtStartOfDay())
17 ## Solr indexes the dates in UTC timezone.
18 #set ($utcTimezone = $xwiki.jodatime.getTimezone(0))
19 #set ($startOfToday = $startOfToday.toDateTime($utcTimezone))
20 #set ($startOfTomorrow = $startOfToday.plusDays(1))
21 #set ($intervals = [
22 {
23 'label': $services.localization.render('solr.facet.date.today'),
24 'start': $startOfToday,
25 'end' : $startOfTomorrow,
26 'name' : '[NOW/DAY TO NOW/DAY+1DAY}',
27 'count': 0
28 }, {
29 'label': $services.localization.render('solr.facet.date.last7Days'),
30 'start': $startOfToday.minusDays(7),
31 'end' : $startOfTomorrow,
32 'name' : '[NOW/DAY-7DAYS TO NOW/DAY+1DAY}',
33 'count': 0
34 }, {
35 'label': $services.localization.render('solr.facet.date.last30Days'),
36 'start': $startOfToday.minusDays(30),
37 'end' : $startOfTomorrow,
38 'name' : '[NOW/DAY-30DAYS TO NOW/DAY+1DAY}',
39 'count': 0
40 }, {
41 'label': $services.localization.render('solr.facet.date.olderThan30Days'),
42 'end' : $startOfToday.minusDays(30),
43 'name' : '[* TO NOW/DAY-30DAYS}',
44 'count': 0
45 }
46 ])
47 ## 2. Date intervals specified on the request.
48 #set ($iso8601Formatter = $xwiki.jodatime.getDateTimeFormatterForPattern($iso8601DateFormat))
49 #set ($iso8601Formatter = $iso8601Formatter.withZone($utcTimezone))
50 #if ($facetRequestValues)
51 #set ($selectedIntervals = [])
52 #foreach ($selectedValue in $facetRequestValues)
53 ## Determine if the value/range is custom.
54 #set ($custom = true)
55 #foreach ($interval in $intervals)
56 #if ($interval.name == $selectedValue)
57 #set ($discard = $selectedIntervals.add($interval))
58 #set ($custom = false)
59 #break
60 #end
61 #end
62 #if ($custom)
63 #set ($rangeMatcher = $rangePattern.matcher($selectedValue))
64 #if ($rangeMatcher.matches())
65 #set ($range = [$rangeMatcher.group(1), $rangeMatcher.group(2)])
66 #foreach ($point in $range)
67 #if ($point == '*')
68 #set ($point = $NULL)
69 #else
70 #set ($point = $iso8601Formatter.parseDateTime($point))
71 #end
72 #set ($discard = $range.set($foreach.index, $point))
73 #end
74 #set ($discard = $selectedIntervals.add({
75 'start': $range.get(0),
76 'end' : $range.get(1),
77 'name' : $selectedValue,
78 'count': 0
79 }))
80 #end
81 #end
82 #end
83 #set ($intervals = $selectedIntervals)
84 #end
85 ##
86 ## Count matches for each date interval.
87 ##
88 #foreach ($facetValue in $facetValues)
89 #set ($dateValue = $iso8601Formatter.parseDateTime($facetValue.name))
90 #foreach ($interval in $intervals)
91 #if ((!$interval.start || $dateValue.compareTo($interval.start) >= 0)
92 && (!$interval.end || $dateValue.compareTo($interval.end) < 0))
93 #set ($discard = $interval.put('count', $mathtool.add($interval.count, $facetValue.count)))
94 #end
95 #end
96 #end
97 ## Filter the unselected date intervals that don't have matches.
98 #if (!$facetRequestValues)
99 #set ($intervalsWithMatches = [])
100 #foreach ($interval in $intervals)
101 #if ($interval.count > 0)
102 #set ($discard = $intervalsWithMatches.add($interval))
103 #end
104 #end
105 #set ($intervals = $intervalsWithMatches)
106 #end
107 ##
108 ## Display date intervals.
109 ##
110 <ul>
111 #foreach ($facetValue in $intervals)
112 <li>#displaySearchFacetValue($facetValue {} 'displaySearchFacetValue_date')</li>
113 #end
114 #if (!$facetRequestValues)
115 ## Allow users to specify a custom interval.
116 <li class="customDateInterval">
117 #displaySearchFacetValue_customDateInterval()
118 </li>
119 #end
120 </ul>
121 #end
122
123 #macro (displaySearchFacetValue_customDateInterval)
124 #set ($dateFormat = $xwiki.getXWikiPreference('dateformat', $defaultDateFormat))
125 <label>
126 <input type="checkbox" class="hidden" />
127 <span class="itemName">
128 $escapetool.xml($services.localization.render('solr.facet.date.customInterval'))
129 </span>
130 </label>
131 <form action="$xwiki.getURL('Main.SolrDateFacet', 'get')">
132 <div class="hidden">
133 ## Reset the pagination because the number of results can change when a facet is applied.
134 #extendQueryString($url {
135 $facetRequestParameter: ['[* TO *]'],
136 'firstIndex': [],
137 'timezoneOffset': []
138 })
139 <input type="hidden" name="xredirect" value="$escapetool.xml($url)" />
140 <input type="hidden" name="facet" value="$escapetool.xml($facetRequestParameter)" />
141 ## This will be overwritten on the client side (with the TimeZone indicated by the browser).
142 #set ($timeZoneOffset = $datetool.timeZone.getOffset($datetool.date.time) / 60000)
143 <input type="hidden" name="timezoneOffset" value="$timeZoneOffset" />
144 </div>
145 <dl>
146 <dt class="hidden">
147 <label for="$escapetool.xml($facetRequestParameter)_startDate">
148 $escapetool.xml($services.localization.render('solr.facet.date.start'))
149 </label>
150 </dt>
151 <dd>
152 #set ($startDatePickerParams = {
153 'id': "${facetRequestParameter}_startDate",
154 'name': 'startDate',
155 'data-format': $dateFormat,
156 'placeholder': $services.localization.render('solr.facet.date.start')
157 })
158 #dateTimePicker($startDatePickerParams)
159 </dd>
160 <dt class="hidden">
161 <label for="$escapetool.xml($facetRequestParameter)_endDate">
162 $escapetool.xml($services.localization.render('solr.facet.date.end'))
163 </label>
164 </dt>
165 <dd>
166 #set ($endDatePickerParams = {
167 'id': "${facetRequestParameter}_endDate",
168 'name': 'endDate',
169 'data-format': $dateFormat,
170 'placeholder': $services.localization.render('solr.facet.date.end')
171 })
172 #dateTimePicker($endDatePickerParams)
173 </dt>
174 </dl>
175 <div>
176 <span class="buttonwrapper">
177 <input type="submit" class="button" value="$escapetool.xml($services.localization.render(
178 'solr.facet.date.applyCustomInterval'))" />
179 </span>
180 </div>
181 </form>
182 #end
183
184 #macro (displaySearchFacetValue_date $facetPrettyValue)
185 #if ($facetValue.label)
186 $escapetool.xml($facetValue.label)
187 #elseif ($facetValue.start || $facetValue.end)
188 ## Compute the client timezone.
189 #set ($timezoneOffsetInMinutes = $numbertool.toNumber($request.timezoneOffset).intValue())
190 #set ($offsetHours = $timezoneOffsetInMinutes / 60)
191 #set ($offsetMinutes = $mathtool.abs($timezoneOffsetInMinutes) % 60)
192 #set ($clientTimezone = $xwiki.jodatime.getTimezone($offsetHours, $offsetMinutes))
193 ## Obtain a date printer.
194 #set ($configuredDateFormat = $xwiki.getXWikiPreference('dateformat', $defaultDateFormat))
195 #set ($datePrinter = $xwiki.jodatime.getDateTimeFormatterForPattern($configuredDateFormat))
196 #set ($datePrinter = $datePrinter.withLocale($services.localization.currentLocale).withZone($clientTimezone))
197 ## Display the custom interval.
198 #if (!$facetValue.start)
199 $escapetool.xml($services.localization.render('solr.facet.date.before',
200 [$datePrinter.print($facetValue.end)]))
201 #elseif (!$facetValue.end)
202 $escapetool.xml($services.localization.render('solr.facet.date.after',
203 [$datePrinter.print($facetValue.start)]))
204 #else
205 $services.localization.render('solr.facet.date.between',
206 ["$datePrinter.print($facetValue.start)<br/>", $datePrinter.print($facetValue.end)])
207 #end
208 #else
209 $escapetool.xml($services.localization.render('solr.facet.date.any'))
210 #end
211 #end
212
213 #macro (convertDateFormat $dateString $inputFormat $dateParser $datePrinter $return)
214 ## We don't use the given date parser directly because it can throw IllegalArgumentException.
215 #set ($date = $datetool.toDate($inputFormat, $dateString, $services.localization.currentLocale))
216 #if ($date)
217 #set ($date = $datePrinter.print($dateParser.parseDateTime($dateString)))
218 #else
219 #set ($date = '*')
220 #end
221 #set ($return = $NULL)
222 #setVariable("$return" $date)
223 #end
224
225 #macro (handleCustomDateInterval)
226 ## Compute the client timezone.
227 #set ($timezoneOffsetInMinutes = $numbertool.toNumber($request.timezoneOffset).intValue())
228 #set ($offsetHours = $timezoneOffsetInMinutes / 60)
229 #set ($offsetMinutes = $mathtool.abs($timezoneOffsetInMinutes) % 60)
230 #set ($clientTimezone = $xwiki.jodatime.getTimezone($offsetHours, $offsetMinutes))
231 ## Obtain a date parser.
232 #set ($configuredDateFormat = $xwiki.getXWikiPreference('dateformat', $defaultDateFormat))
233 #set ($dateParser = $xwiki.jodatime.getDateTimeFormatterForPattern($configuredDateFormat))
234 #set ($dateParser = $dateParser.withLocale($services.localization.currentLocale).withZone($clientTimezone))
235 ## Obtain a date printer (Solr indexes the dates in ISO8601 format with UTC timezone).
236 #set ($datePrinter = $xwiki.jodatime.getDateTimeFormatterForPattern($iso8601DateFormat))
237 #set ($utcTimezone = $xwiki.jodatime.getTimezone(0))
238 #set ($datePrinter = $datePrinter.withZone($utcTimezone))
239 ## Convert the given dates.
240 #convertDateFormat($request.startDate $configuredDateFormat $dateParser $datePrinter $startDate)
241 #convertDateFormat($request.endDate $configuredDateFormat $dateParser $datePrinter $endDate)
242 #set ($interval = "[$startDate TO $endDate}")
243 #set ($xredirect = $request.xredirect.replaceFirst(
244 "\b$regextool.quote($escapetool.url($request.facet))=[^&$escapetool.d]*",
245 $escapetool.url({
246 $request.facet: $interval,
247 'timezoneOffset': $request.timezoneOffset
248 })))
249 $response.sendRedirect($xredirect)
250 #end
251 {{/velocity}}
252
253 {{velocity}}
254 #if ($xcontext.action == 'get' && "$!request.facet" != '' && ($request.startDate || $request.endDate))
255 #handleCustomDateInterval()
256 #elseif ($facetValues)
257 {{html clean="false"}}#displaySearchFacetValues_date($facetValues){{/html}}
258 #end
259 {{/velocity}}
#getBlogDocument($space $blogDoc)
XWiki Enterprise 14.6 - Documentation