aboutsummaryrefslogtreecommitdiffstats
path: root/isuifang_solr/solr/conf/velocity/VM_global_library.vm
blob: 3dd880c46ba6d4b71a9efd7ab4183366308fa5c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

#macro(param $key)$request.params.get($key)#end

#macro(url_for_solr)/solr#if($request.core.name != "")/$request.core.name#end#end
#macro(url_for_home)#url_for_solr/browse#end

#macro(q)&q=$!{esc.url($params.get('q'))}#end

#macro(fqs $p)#foreach($fq in $p)#if($velocityCount>1)&#{end}fq=$esc.url($fq)#end#end

#macro(debug)#if($request.params.get('debugQuery'))&debugQuery=true#end#end

#macro(boostPrice)#if($request.params.get('bf') == 'price')&bf=price#end#end        

#macro(annotate)#if($request.params.get('annotateBrowse'))&annotateBrowse=true#end#end

#macro(annTitle $msg)#if($annotate == true)title="$msg"#end#end

#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

#macro(qOpts)#set($queryOpts = $request.params.get("queryOpts"))#if($queryOpts && $queryOpts != "")&queryOpts=$queryOpts#end#end

#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

#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
#macro(lens)#lensNoQ#q#end
        

#macro(url_for_lens)#{url_for_home}#lens#end

#macro(url_for_start $start)#url_for_home#lens&start=$start#end

#macro(url_for_filters $p)#url_for_home?#q#boostPrice#spatial#qOpts#if($list.size($p) > 0)&#fqs($p)#end#debug#end


#macro(url_for_nested_facet_query $field)#url_for_home#lens&fq=$esc.url($field)#end

## TODO: convert to use {!raw f=$field}$value (with escaping of course)
#macro(url_for_facet_filter $field $value)#url_for_home#lens&fq=$esc.url($field):%22$esc.url($value)%22#end

#macro(url_for_facet_date_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end

#macro(url_for_facet_range_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end


#macro(link_to_previous_page $text)
  #if($page.current_page_number > 1)
    #set($prev_start = $page.start - $page.results_per_page)
    <a class="prev-page" href="#url_for_start($prev_start)">$text</a>
  #end
#end

#macro(link_to_next_page $text)
  #if($page.current_page_number < $page.page_count)
    #set($next_start = $page.start + $page.results_per_page)
    <a class="next-page" href="#url_for_start($next_start)">$text</a>
  #end
#end

#macro(link_to_page $page_number $text)
  #if($page_number == $page.current_page_number)
    $text
  #else
    #if($page_number <= $page.page_count)
      #set($page_start = $page_number * $page.results_per_page - $page.results_per_page)
      <a class="page" href="#url_for_start($page_start)">$text</a>
    #end
  #end
#end

#macro(display_facet_query $field, $display, $fieldName)
  #if($field.size() > 0)
  <span class="facet-field">$display</span>
    <ul>
    #foreach ($facet in $field)
      #if ($facet.value > 0)
        #set($facetURL = "#url_for_nested_facet_query($facet.key)")
        #if ($facetURL != '')
          <li><a href="$facetURL">$facet.key</a> ($facet.value)</li>
        #end
      #end
    #end
    </ul>
  #end      
#end


#macro(display_facet_range $field, $display, $fieldName, $start, $end, $gap, $before, $after)
  <span class="facet-field">$display</span>
    <ul>
    #if($before && $before != "")
      #set($value = "[* TO " + "#format_value($start)" + "]")
      #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")
      <li><a href="$facetURL">Less than #format_value($start)</a> ($before)</li>
    #end
    #foreach ($facet in $field)
      #set($rangeEnd = "#range_get_to_value($facet.key, $gap)")
      #set($value = "[" + $facet.key + " TO " + $rangeEnd + "]")
      #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")
      #if ($facetURL != '')
        <li><a href="$facetURL">$facet.key - #format_value($rangeEnd)</a> ($facet.value)</li>
      #end
    #end
    #if($end && $end != "" && $after > 0)
      #set($value = "[" + "#format_value($end)" + " TO *]")
      #set($facetURL = "#url_for_facet_range_filter($fieldName, $value)")
      <li><a href="$facetURL">More than #format_value($end)</a> ($after)</li>
    #end
    </ul>
#end

## $pivots is a list of facet_pivot
#macro(display_facet_pivot $pivots, $display)
  #if($pivots.size() > 0)
  <span class="facet-field">$display</span>
    <ul>
      #foreach ($pivot in $pivots)
        #foreach ($entry in $pivot.value)
          <a href="#url_for_facet_filter($entry.field, $entry.value)">$entry.field::$entry.value</a> ($entry.count)
          <ul>
            #foreach($nest in $entry.pivot)
              <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)
            #end
          </ul>
        #end
      #end
    </ul>
  #end
#end

#macro(field $f)
  #if($response.response.highlighting.get($docId).get($f).get(0))
    $!response.response.highlighting.get($docId).get($f).get(0)
  #else
    #foreach($v in $doc.getFieldValues($f))
      $v
    #end
  #end
#end  

#macro(utc_date $theDate)
$date.format("yyyy-MM-dd'T'HH:mm:ss'Z'",$theDate,$date.getLocale(),$date.getTimeZone().getTimeZone("UTC"))##
#end

#macro(format_value $val)
#if(${val.class.name} == "java.util.Date")
#utc_date($val)##
#else
$val##
#end
#end

#macro(range_get_to_value $inval, $gapval)
#if(${gapval.class.name} == "java.lang.String")
$inval$gapval##
#elseif(${gapval.class.name} == "java.lang.Float" || ${inval.class.name} == "java.lang.Float")
$math.toDouble($math.add($inval,$gapval))##
#else
$math.add($inval,$gapval)##
#end
#end