1 | <?php |
---|
2 | $sf_response->setTitle("Recherche de $query"); $style = "xneth"; |
---|
3 | |
---|
4 | function url_search($query, $args) |
---|
5 | { |
---|
6 | $extra = ''; |
---|
7 | $url = "solr/search?query=".$query; |
---|
8 | foreach($args as $key => $value) { |
---|
9 | if (is_array($value)) { |
---|
10 | if (count($value)) { $extra .= '&'.$key.'='.implode(',', array_keys($value)); } |
---|
11 | } |
---|
12 | else { $extra .= '&'.$key.'='.$value; } |
---|
13 | } |
---|
14 | return $url.$extra; |
---|
15 | } |
---|
16 | |
---|
17 | function link_search($text, $query, $args, $options) |
---|
18 | { |
---|
19 | if($options) { return link_to($text, url_search($query, $args), $options); } |
---|
20 | else { return link_to($text, url_search($query, $args)); } |
---|
21 | } |
---|
22 | |
---|
23 | function addToDate($date, $interval) { |
---|
24 | $date = preg_replace('/\-/', '', $date); |
---|
25 | $annee = substr($date, 0, 4); |
---|
26 | $mois = substr($date, 4, 2); |
---|
27 | $jour = substr($date, 6, 2); |
---|
28 | if($interval == 'mois') { |
---|
29 | $date = mktime(0, 0, 0, $mois + 1, $jour, $annee); |
---|
30 | #int mktime ("H","m","s","M","j","Y", -1) |
---|
31 | } |
---|
32 | else { $date = mktime(0, 0, 0, $mois, $jour - 1, $annee); } |
---|
33 | $date = date("Ymd", $date); |
---|
34 | return $date; |
---|
35 | } |
---|
36 | |
---|
37 | $recherche = preg_replace('/"/', '"', $query); |
---|
38 | |
---|
39 | switch ($vue) { |
---|
40 | case "jour": |
---|
41 | $periode_text = 'le '.myTools::displayShortDate($start); |
---|
42 | $intitule_resultats = 'Résultats pour "<em>'.$recherche.'</em>" '.$periode_text; |
---|
43 | $graph = 0; |
---|
44 | break; |
---|
45 | case "mois": |
---|
46 | $periode_text = 'en '.myTools::displayMoisAnnee($start); |
---|
47 | $intitule_resultats = 'Résultats pour "<em>'.$recherche.'</em>" '; |
---|
48 | $graph = 1; |
---|
49 | break; |
---|
50 | case "par_jour": |
---|
51 | $periode_text = 'entre le '.myTools::displayShortDate($start).' et le '.myTools::displayShortDate($end); |
---|
52 | $intitule_resultats = 'Résultats pour "<em>'.$recherche.'</em>" '; |
---|
53 | $graph = 1; |
---|
54 | break; |
---|
55 | case "par_mois": |
---|
56 | $periode_text = 'entre '.myTools::displayMoisAnnee($start).' et '.myTools::displayMoisAnnee($end); |
---|
57 | $intitule_resultats = 'Résultats pour "<em>'.$recherche.'</em>" '; |
---|
58 | $graph = 1; |
---|
59 | break; |
---|
60 | default: |
---|
61 | $periode_text = "supprimer les critère de dates"; |
---|
62 | $intitule_resultats = 'Recherche de "<em>'.$recherche.'</em>'; |
---|
63 | $graph = 1; |
---|
64 | } |
---|
65 | |
---|
66 | //////////////////// DEBUT SANS AJAX ///////////////////// |
---|
67 | ////////////////////////////////////////////////////////// |
---|
68 | |
---|
69 | if (!$ajax) : |
---|
70 | ?> |
---|
71 | <script type="text/javascript"> |
---|
72 | <!-- |
---|
73 | function urlParams(params) { |
---|
74 | param = new Object(); |
---|
75 | if(jQuery.isArray(params)) { |
---|
76 | jQuery.each(params, function() { |
---|
77 | val = this.split('='); |
---|
78 | param[val[0]] = val[1]; |
---|
79 | }); |
---|
80 | } |
---|
81 | else { |
---|
82 | val = params.split('='); |
---|
83 | param[val[0]] = val[1]; |
---|
84 | } |
---|
85 | return param; |
---|
86 | } |
---|
87 | |
---|
88 | periode = new Array(); |
---|
89 | date_href = new Array(); |
---|
90 | nb_li = 0; |
---|
91 | bh = 0; |
---|
92 | nh = 0; |
---|
93 | if(location.search.substring(1)) { parametre = urlParams(location.search.substring(1).split('&')); } |
---|
94 | else { parametre = new Object(); } |
---|
95 | |
---|
96 | timer4update = null; |
---|
97 | function realAjaxUpdate(lien) { |
---|
98 | lien += '&ajax=1'; |
---|
99 | $('#results_container').load(lien, function() {$('#results_container').fadeTo(100,1);}); |
---|
100 | } |
---|
101 | function ajaxUpdateFor(lien) { |
---|
102 | if (timer4update) { |
---|
103 | clearTimeout(timer4update); |
---|
104 | timer4update = null; |
---|
105 | } |
---|
106 | $('#results_container').css('opacity', 0.5); |
---|
107 | timer4update = setTimeout('realAjaxUpdate("'+lien+'")', 2500); |
---|
108 | } |
---|
109 | |
---|
110 | function constructLien(date) { |
---|
111 | lien = document.location+''; |
---|
112 | lien = lien.replace(/\??date=[^&]+/, ''); |
---|
113 | lien = lien.replace(/#.*/, ''); |
---|
114 | if (!lien.match(/\?/)) |
---|
115 | lien += '?'; |
---|
116 | else |
---|
117 | lien += '&'; |
---|
118 | lien += 'date='+date; |
---|
119 | return lien; |
---|
120 | } |
---|
121 | |
---|
122 | $(document).ready(function() { |
---|
123 | $(".date li").each(function() { |
---|
124 | if($(this).height() > bh) { bh = $(this).height(); } |
---|
125 | date_li = $(this).attr("title").split('--'); |
---|
126 | date_href[nb_li] = $(this).find('a').attr("href"); |
---|
127 | $(this).find(".hover_graph").attr("onclick", "document.location.replace('http://"+location.host+date_href[nb_li]+"')"); |
---|
128 | $(this).find(".hover_graph").css("cursor", "pointer"); |
---|
129 | periode[nb_li] = date_li[0]; |
---|
130 | nb_li++; |
---|
131 | }); |
---|
132 | if(bh <= 30) { |
---|
133 | $(".date li").each(function() { |
---|
134 | nh = $(this).height() * 2; $(this).height(nh); |
---|
135 | }); |
---|
136 | bh = bh * 2; |
---|
137 | } |
---|
138 | if(bh <= 170) { bh = bh + 30; $(".date").height(bh); } |
---|
139 | $(".date").fadeIn(300); /* à revoir */ |
---|
140 | $(function() { |
---|
141 | $("#slider_date_graph").slider({ |
---|
142 | range: true, |
---|
143 | min: 0, |
---|
144 | max: nb_li-1, |
---|
145 | values: [0, nb_li], |
---|
146 | slide: function(event, ui) { |
---|
147 | from = date_href[ui.values[0]].split('?'); |
---|
148 | from = urlParams(from[1].split('&')); |
---|
149 | from = from["date"].split('%2C'); |
---|
150 | to = date_href[ui.values[1]].split('?'); |
---|
151 | to = urlParams(to[1].split('&')); |
---|
152 | to = to["date"].split('%2C'); |
---|
153 | parametre["date"] = from[0]+'%2C'+to[0]; |
---|
154 | |
---|
155 | lien = constructLien(parametre['date']); |
---|
156 | document.location = '#date='+parametre['date']; |
---|
157 | |
---|
158 | if(ui.values[0] == ui.values[1]) { |
---|
159 | texte_periode = '<a href="'+lien+'" style="text-decoration: underline;"><strong>'+periode[ui.values[0]].toLowerCase()+'<`\/strong><\/a>'; |
---|
160 | } |
---|
161 | else { |
---|
162 | texte_periode = '<a href="'+lien+'" style="text-decoration: underline;"><strong>entre '+periode[ui.values[0]].toLowerCase()+' et '+ periode[ui.values[1]].toLowerCase()+'<\/strong><\/a>'; |
---|
163 | } |
---|
164 | ajaxUpdateFor(lien); |
---|
165 | $("#periode").text(""); |
---|
166 | $("#periode").append(texte_periode); |
---|
167 | } |
---|
168 | }); |
---|
169 | $("#periode").text('entre ' + periode[$("#slider_date_graph").slider("values", 0)].toLowerCase() + ' et ' + periode[$("#slider_date_graph").slider("values", 1)].toLowerCase()); |
---|
170 | }); |
---|
171 | }); |
---|
172 | //--> |
---|
173 | </script> |
---|
174 | |
---|
175 | <div class="solr"> |
---|
176 | <?php include_partial('solr/searchbox'); ?> |
---|
177 | <h1><?php echo $intitule_resultats; ?></h1> |
---|
178 | <?php |
---|
179 | if($graph) { |
---|
180 | $width_date = 900; |
---|
181 | $left = 2; |
---|
182 | $espacement = 4; |
---|
183 | $width = (($width_date - $left) / count($fdates['values'])) - $espacement; |
---|
184 | ?> |
---|
185 | <div class="cont_date_graph"> |
---|
186 | <span>Affiner par date :</span> <span id="periode"><?php echo $periode_text; ?></span> |
---|
187 | <div class="date" style="width: <?php echo $width_date ?>px;"> |
---|
188 | <ul> |
---|
189 | <?php $i = 0; foreach($fdates['values'] as $date => $nb) : |
---|
190 | $i++; |
---|
191 | $height = round($nb['pc']*100/($fdates['max']) * 2); |
---|
192 | $padding = 200-$height; |
---|
193 | $left = $left + $width; if($i < (count($fdates['values']))) { $left = $left + $espacement; } |
---|
194 | $newargs = $selected; |
---|
195 | |
---|
196 | $newargs['date'] = $date.'%2C'.$date; |
---|
197 | |
---|
198 | if(($vue == 'jour') or ($vue == 'par_jour') or ($vue == 'mois')){ |
---|
199 | $title_date = myTools::displayShortDate($date).' -- '.$nb['nb'].' résultats'; |
---|
200 | } |
---|
201 | if($vue == 'par_mois') { |
---|
202 | $title_date = ucfirst(myTools::displayMoisAnnee($date)).' -- '.$nb['nb'].' résultats'; |
---|
203 | } |
---|
204 | if($vue == 'par_mois') { |
---|
205 | $newargs['date'] = $date.'%2C'.addToDate($date, 'mois'); |
---|
206 | } |
---|
207 | |
---|
208 | echo '<li title="'.$title_date.'" class="jstitle" style="list-style-image: none; width: '.$width.'px; height: '.$height.'px; left: '.$left.'px;">'; |
---|
209 | echo '<div class="hover_graph" style="width: '.$width.'px; height: '.$padding.'px; bottom: '.$height.'px;"></div><span class="text_graph">'.link_search($nb['nb'], $query, $newargs, array()).'</span>'; |
---|
210 | |
---|
211 | # echo ' '.$nb['nb'].' résultats ('; printf('%02d', $nb['pc']*100/($fdates['max'])); echo '%)'; |
---|
212 | ?> |
---|
213 | </li> |
---|
214 | <?php endforeach; ?> |
---|
215 | </ul> |
---|
216 | </div> |
---|
217 | <div id="slider_date_graph"></div> |
---|
218 | </div> |
---|
219 | <?php } ?> |
---|
220 | <div id="results_container"> |
---|
221 | <?php |
---|
222 | endif; |
---|
223 | ///////////////////// FIN SANS AJAX ///////////////////// |
---|
224 | ?> |
---|
225 | <div class="nb_results"> |
---|
226 | <h2>Résultats <?php echo $results['start']+1; ?> à <?php echo min($results['end'],$results['numFound']); ?> sur <?php echo $results['numFound']; ?> <strong>triés par <?php echo $sort_type; ?></strong> - |
---|
227 | <span class="tri"> |
---|
228 | <?php |
---|
229 | $newargs = $selected; |
---|
230 | if ($sort) { |
---|
231 | if (isset($newargs['sort'])) { $newargs['sort'] = 0; } |
---|
232 | echo link_search('trier par pertinence', $query, $newargs, 0); |
---|
233 | } |
---|
234 | else { |
---|
235 | $newargs['sort'] = 1; |
---|
236 | echo link_search('trier par date', $query, $newargs, 0); |
---|
237 | } |
---|
238 | ?> |
---|
239 | </span></h2> |
---|
240 | </div> |
---|
241 | <div class="options"> |
---|
242 | <div class="mail"> |
---|
243 | <h3>Alerte email</h3> |
---|
244 | <?php |
---|
245 | $args = ''; |
---|
246 | foreach(array_keys($selected) as $k) { |
---|
247 | if (!is_array($selected[$k]) || $k == 'date') |
---|
248 | continue; |
---|
249 | if ($args) |
---|
250 | $args .= '&'; |
---|
251 | $args.= "$k=".implode(',', array_keys($selected[$k])); |
---|
252 | } |
---|
253 | echo link_to('Recevoir un email lorsque de nouveaux résultats seront publiés pour cette recherche', 'alerte/create?filter='.urlencode($args).'&query='.urlencode($query)); |
---|
254 | |
---|
255 | global $facetName2HumanName; |
---|
256 | $facetName2HumanName = array( |
---|
257 | 'Parlementaires' => 'Filtrer par député', |
---|
258 | 'Parlementaire' => 'Députés', |
---|
259 | 'Types' => 'Filtrer par type de document', |
---|
260 | 'Tags' => 'Filtrer par tags', |
---|
261 | 'Texteloi' => 'Documents parlementaires', |
---|
262 | 'QuestionEcrite' => 'Questions écrites', |
---|
263 | 'Tags' => 'Filtrer par tags' |
---|
264 | ); |
---|
265 | function facet2Human($id) { |
---|
266 | global $facetName2HumanName; |
---|
267 | if (!isset($facetName2HumanName[$id])) { |
---|
268 | return $id; |
---|
269 | } |
---|
270 | return $facetName2HumanName[$id]; |
---|
271 | } |
---|
272 | ?> |
---|
273 | </div> |
---|
274 | <div class="facets"> |
---|
275 | <h3>Affiner la recherche</h3> |
---|
276 | <?php |
---|
277 | if(isset($newargs['date'])) { |
---|
278 | $args_sans_date = $newargs; |
---|
279 | unset($args_sans_date['date']); |
---|
280 | echo '<p><strong>Filtrer par dates</strong></p><ul><li class="selected">'.link_search($periode_text, $query, $args_sans_date, 0).'</li></ul>'; |
---|
281 | } |
---|
282 | |
---|
283 | foreach(array_keys($facet) as $k) { if (isset($facet[$k]['values']) && count($facet[$k]['values'])) : ?> |
---|
284 | <div class="<?php echo $k; ?>"> |
---|
285 | <p><strong><?php echo facet2Human($facet[$k]['name']); ?></strong></p> |
---|
286 | <ul> |
---|
287 | <?php foreach($facet[$k]['values'] as $value => $nb) : if ($nb) : |
---|
288 | $is_selected = isset($selected[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value]) && |
---|
289 | $selected[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value]; |
---|
290 | ?> |
---|
291 | <li<?php if ($is_selected) echo ' class="selected"'; ?>><?php |
---|
292 | $newargs = $selected; |
---|
293 | if ($is_selected) |
---|
294 | unset($newargs[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value]); |
---|
295 | else |
---|
296 | $newargs[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value] = 1; |
---|
297 | echo link_search(facet2Human($value), $query, $newargs, 0); ?> (<?php echo $nb; ?>) |
---|
298 | </li> |
---|
299 | <?php endif; endforeach; ?> |
---|
300 | </ul> |
---|
301 | </div> |
---|
302 | <?php endif; } ?> |
---|
303 | </div> |
---|
304 | </div> |
---|
305 | <div class="results"> |
---|
306 | <?php foreach ($results['docs'] as $record) : ?> |
---|
307 | <div class="item"> |
---|
308 | <h4><a href="<?php echo $record['link']; ?>"><?php echo $record['titre']; ?></a></h4> |
---|
309 | <?php if ($record['photo']) { ?> |
---|
310 | <p class="photo"><a href="<?php echo $record['link']; ?>" rel="nofollow"><?php echo $record['photo']; ?></a></p> |
---|
311 | <?php } ?> |
---|
312 | <p class="intervenant"><a href="<?php echo $record['link']; ?>" rel="nofollow"><?php echo $record['personne']; ?></a></p> |
---|
313 | <p class="content"><?php echo $record['highlighting']; ?></p> |
---|
314 | <p class="more"><a href="<?php echo $record['link']; ?>">Consulter</a></p> |
---|
315 | </div> |
---|
316 | <div class="record"> |
---|
317 | </div> |
---|
318 | <?php endforeach; ?> |
---|
319 | </div> |
---|
320 | <div class="pager"> |
---|
321 | <div class="next"> |
---|
322 | <?php |
---|
323 | if ($results['end']-1 != $results['numFound']) { |
---|
324 | $newargs = $selected; |
---|
325 | $newargs['page'][$results['page'] + 1] = 1; |
---|
326 | echo link_search('page suivante', $query, $newargs, 0); |
---|
327 | } |
---|
328 | ?> |
---|
329 | </div> |
---|
330 | <div class="last"> |
---|
331 | <?php |
---|
332 | $newargs = $selected; |
---|
333 | $newargs['page'][$results['page'] - 1] = 1; |
---|
334 | if ($results['page'] > 1) { |
---|
335 | if (isset($newargs['page'][1])) |
---|
336 | unset($newargs['page'][1]); |
---|
337 | echo link_search('page précédente', $query, $newargs, 0); |
---|
338 | } |
---|
339 | ?> |
---|
340 | </div> |
---|
341 | </div> |
---|
342 | </div> |
---|
343 | <?php if (!$ajax) : ?> |
---|
344 | </div> |
---|
345 | <?php endif; ?> |
---|