rss
[prawokultury.git] / doc / solr-conf / velocity / VM_global_library.vm
1
2 #macro(param $key)$request.params.get($key)#end
3
4 #macro(url_root)/solr#end
5
6 ## TODO: s/url_for_solr/url_for_core/ and s/url_root/url_for_solr/
7 #macro(core_name)$request.core.name#end
8 #macro(url_for_solr)#{url_root}#if($request.core.name != "")/$request.core.name#end#end
9 #macro(url_for_home)#url_for_solr/browse#end
10
11 #macro(q)&q=$!{esc.url($params.get('q'))}#end
12
13 #macro(fqs $p)#foreach($fq in $p)#if($velocityCount>1)&#{end}fq=$esc.url($fq)#end#end
14
15 #macro(debug)#if($request.params.get('debugQuery'))&debugQuery=true#end#end
16
17 #macro(boostPrice)#if($request.params.get('bf') == 'price')&bf=price#end#end        
18
19 #macro(annotate)#if($request.params.get('annotateBrowse'))&annotateBrowse=true#end#end
20
21 #macro(annTitle $msg)#if($annotate == true)title="$msg"#end#end
22
23 #macro(spatial)#if($request.params.get('sfield'))&sfield=store#end#if($request.params.get('pt'))&pt=$request.params.get('pt')#end#if($request.params.get('d'))&d=$request.params.get('d')#end#end
24
25 #macro(qOpts)#set($queryOpts = $request.params.get("queryOpts"))#if($queryOpts && $queryOpts != "")&queryOpts=$queryOpts#end#end
26
27 #macro(group)#if($request.params.getBool("group") == true)&group=true#end#if($request.params.get("group.field"))#foreach($grp in $request.params.getParams('group.field'))&group.field=$grp#end#end#end
28
29 #macro(lensNoQ)?#if($request.params.getParams('fq') and $list.size($request.params.getParams('fq')) > 0)&#fqs($request.params.getParams('fq'))#end#debug#boostPrice#annotate#spatial#qOpts#group#end
30 #macro(lens)#lensNoQ#q#end
31         
32
33 #macro(url_for_lens)#{url_for_home}#lens#end
34
35 #macro(url_for_start $start)#url_for_home#lens&start=$start#end
36
37 #macro(url_for_filters $p)#url_for_home?#q#boostPrice#spatial#qOpts#if($list.size($p) > 0)&#fqs($p)#end#debug#end
38
39 #macro(url_for_nested_facet_query $field)#url_for_home#lens&fq=$esc.url($field)#end
40
41 ## TODO: convert to use {!raw f=$field}$value (with escaping of course)
42 #macro(url_for_facet_filter $field $value)#url_for_home#lens&fq=$esc.url($field):%22$esc.url($value)%22#end
43
44 #macro(url_for_facet_date_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end
45
46 #macro(url_for_facet_range_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end
47
48
49 #macro(link_to_previous_page $text)
50   #if($page.current_page_number > 1)
51     #set($prev_start = $page.start - $page.results_per_page)
52     <a class="prev-page" href="#url_for_start($prev_start)">$text</a>
53   #end
54 #end
55
56 #macro(link_to_next_page $text)
57   #if($page.current_page_number < $page.page_count)
58     #set($next_start = $page.start + $page.results_per_page)
59     <a class="next-page" href="#url_for_start($next_start)">$text</a>
60   #end
61 #end
62
63 #macro(link_to_page $page_number $text)
64   #if($page_number == $page.current_page_number)
65     $text
66   #else
67     #if($page_number <= $page.page_count)
68       #set($page_start = $page_number * $page.results_per_page - $page.results_per_page)
69       <a class="page" href="#url_for_start($page_start)">$text</a>
70     #end
71   #end
72 #end
73
74 #macro(display_facet_query $field, $display, $fieldName)
75   #if($field.size() > 0)
76   <span class="facet-field">$display</span>
77     <ul>
78     #foreach ($facet in $field)
79       #if ($facet.value > 0)
80         #set($facetURL = "#url_for_nested_facet_query($facet.key)")
81         #if ($facetURL != '')
82           <li><a href="$facetURL">$facet.key</a> ($facet.value)</li>
83         #end
84       #end
85     #end
86     </ul>
87   #end      
88 #end
89
90
91 #macro(display_facet_range $field, $display, $fieldName, $start, $end, $gap, $before, $after)
92   <span class="facet-field">$display</span>
93     <ul>
94     #if($before && $before != "")
95       #set($value = "[* TO " + "#format_value($start)" + "}")
96       #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")
97       <li><a href="$facetURL">Less than #format_value($start)</a> ($before)</li>
98     #end
99     #foreach ($facet in $field)
100       #set($rangeEnd = "#range_get_to_value($facet.key, $gap)")
101       #set($value = "[" + $facet.key + " TO " + $rangeEnd + "}")
102       #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")
103       #if ($facetURL != '')
104         <li><a href="$facetURL">$facet.key - #format_value($rangeEnd)</a> ($facet.value)</li>
105       #end
106     #end
107     #if($end && $end != "" && $after > 0)
108       #set($value = "[" + "#format_value($end)" + " TO *}")
109       #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")
110       <li><a href="$facetURL">More than #format_value($end)</a> ($after)</li>
111     #end
112     </ul>
113 #end
114
115 ## $pivots is a list of facet_pivot
116 #macro(display_facet_pivot $pivots, $display)
117   #if($pivots.size() > 0)
118   <span class="facet-field">$display</span>
119     <ul>
120       #foreach ($pivot in $pivots)
121         #foreach ($entry in $pivot.value)
122           <a href="#url_for_facet_filter($entry.field, $entry.value)">$entry.field::$entry.value</a> ($entry.count)
123           <ul>
124             #foreach($nest in $entry.pivot)
125               <a href="#url_for_facet_filter($entry.field, $entry.value)&fq=$esc.url($nest.field):%22$esc.url($nest.value)%22">$nest.field::$nest.value</a> ($nest.count)
126             #end
127           </ul>
128         #end
129       #end
130     </ul>
131   #end
132 #end
133
134 #macro(field $f)
135   #if($response.response.highlighting.get($docId).get($f).get(0))
136     #set($pad = "")
137     #foreach($v in $response.response.highlighting.get($docId).get($f))
138 $pad$v##
139       #set($pad = " ... ")
140     #end
141   #else
142     #foreach($v in $doc.getFieldValues($f))
143 $v##
144     #end
145   #end
146 #end  
147
148 #macro(utc_date $theDate)
149 $date.format("yyyy-MM-dd'T'HH:mm:ss'Z'",$theDate,$date.getLocale(),$date.getTimeZone().getTimeZone("UTC"))##
150 #end
151
152 #macro(format_value $val)
153 #if(${val.class.name} == "java.util.Date")
154 #utc_date($val)##
155 #else
156 $val##
157 #end
158 #end
159
160 #macro(range_get_to_value $inval, $gapval)
161 #if(${gapval.class.name} == "java.lang.String")
162 $inval$gapval##
163 #elseif(${gapval.class.name} == "java.lang.Float" || ${inval.class.name} == "java.lang.Float")
164 $math.toDouble($math.add($inval,$gapval))##
165 #else
166 $math.add($inval,$gapval)##
167 #end
168 #end