ideation_search_solr_search_results.html
1 <#setting url_escaping_charset=encoding>
2
3 <#-- Getting solr conf -->
4 <#if conf_user_query??>
5 <#assign conf_query = "&conf=${conf_user_query}">
6 <#else>
7 <#assign conf_query = "">
8 </#if>
9
10 <#-- Encode facet queries -->
11 <#assign allParisCity = "-location_text:whole">
12 <#assign allArrParisCity = "location_text:">
13 <#macro EncodeFQ list_fq optionalParam1="" optionalParam2="">
14 <#assign bCheck = false>
15 <#assign encoded_facets_queries = "">
16 <#list list_fq as facet>
17 <#if optionalParam1?has_content && optionalParam2?has_content && facet?starts_with(optionalParam2) >
18 <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+optionalParam1>
19 <#assign bCheck = true>
20 <#else>
21 <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+facet?url>
22 <#if facet?starts_with(optionalParam1)>
23 <#assign bCheck = true>
24 </#if>
25 </#if>
26 </#list>
27 <#if optionalParam1?has_content && optionalParam2?has_content && !bCheck>
28 <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+optionalParam1>
29 </#if>
30 ${encoded_facets_queries}</#macro>
31
32 <#assign sQuery = "">
33
34 <#macro EncodeFQArrondissement list_fq >
35 <#assign encoded_facets_queries = "">
36
37 <#list list_fq as facet>
38 <#if facet?starts_with("location_text") || facet?starts_with("code_theme_string") || facet?starts_with("type") || facet?starts_with("-location_text")>
39 <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+facet?url>
40 </#if>
41 </#list>
42 ${encoded_facets_queries}</#macro>
43
44 <#-- Old code ? Can be removed ? -->
45 <#if query?has_content>
46 <#if !query?starts_with("categorie")>
47 <#if !query?starts_with("(")>
48 <#assign sQuery = "${query}">
49 <#else>
50 <#assign sQuery = "${query?split(' AND')?first?substring(1, query?split(' AND')?first?length)}">
51 </#if>
52 </#if>
53 </#if>
54
55 <#-- Dealing with query -->
56 <#assign sQueryUrlSave = sQuery>
57 <#assign sQuery = sQuery?split(":")?last>
58 <#assign sQueryUrl= sQuery>
59 <#if sQuery?has_content && sQuery?starts_with("(") && sQuery?ends_with(")") >
60 <#assign sQuery = sQuery?remove_beginning("(")>
61 <#assign sQuery = sQuery?remove_ending(")")>
62 </#if>
63
64 <#-- Retreiving current facets filters -->
65 <#assign arr= "">
66 <#assign facet_theme= "">
67 <#assign facet_campaign= "">
68 <#assign facet_field4= "">
69 <#assign facet_qpop= "">
70 <#assign facet_submitter_type= "">
71 <#assign facet_status="">
72 <#assign monTri ="">
73 <#assign ordre_aleatoire= "true">
74 <#assign cadre_de_vie= 'false'>
75 <#assign education_et_jeunesse= 'false'>
76 <#assign logement_et_habitat= 'false'>
77 <#assign environnement= 'false'>
78 <#assign sport= 'false'>
79 <#assign number_random="${.now?long?string}"?number />
80 <#if facets_list??>
81 <#list facets_list as facet>
82 <!-- <input type="hidden" name="fq" value="${facet}" /> -->
83 <#if facet?starts_with("location_text:")> <#assign arr = facet?split(":")?last>
84 <#elseif facet?starts_with("code_theme_string:")> <#assign facet_theme = facet?split(":")?last>
85 <#elseif facet?starts_with("campaign_text:")> <#assign facet_campaign = facet?split(":")?last>
86 <#elseif facet?starts_with("field4_string")> <#assign facet_field4 = facet?split(":")?last>
87 <#elseif facet?starts_with("type_qpvqva_string")> <#assign facet_qpop = facet?split(":")?last>
88 <#elseif facet?starts_with("code_submitter_type_string:")> <#assign facet_submitter_type = facet?split(":")?last>
89 <#elseif facet?starts_with("statut_publique_project_text:")> <#assign facet_status = facet?split(":")?last>
90 </#if>
91 </#list>
92 </#if>
93
94 <#--
95 arr = <strong>${arr!'?'}</strong><br>
96 facet_theme = <strong>${facet_theme!'?'}</strong><br>
97 facet_campaign = <strong>${facet_campaign!'?'}</strong><br>
98 facet_field4 = <strong>${facet_field4!'?'}</strong><br>
99 facet_qpop = <strong>${facet_qpop!'?'}</strong><br>
100 facet_submitter_type = <strong>${facet_submitter_type!'?'}</strong><br>
101 facet_status = <strong>${facet_status!'?'}</strong><br>
102 -->
103
104 <section id="search-prj">
105
106
107 <form id="search-prj-form" name="search" method="get" action="jsp/site/Portal.jsp">
108
109 <input type="hidden" name="page" value="search-solr">
110 <input id="form_conf_hidden" type="hidden" name="conf" value="${conf_user_query}">
111
112 <div id="search-form">
113
114 <h1>#i18n{participatoryideation.search.header.title}</h1>
115
116 <div id="search-prj-fields" class="container form">
117 <div class="row">
118
119 <div class="col-md-12">
120 <#-- Full-text search -->
121 <div class="form-group">
122 <label class="sr-only" for="query">#i18n{participatoryideation.search.form.field.keyword.label}</label>
123 <div class="input-group">
124 <input class="form-control" type="text" name="query" value="${sQuery!}" placeholder="Search by keywords" id="solr"/>
125 <span class="input-group-btn">
126 <button id="btn-search" class="btn btn-search form-control" type="submit" title="Search" onclick="this.disabled=true; searchTri(); return false;">
127 <i class="fa fa-search"></i>
128 </button>
129 </span>
130 </div>
131 <span class="help-txt"></span>
132 </div>
133 </div>
134
135 </div>
136
137 <a class="searchParametersButton visible-xs" href="#searchParameters" data-toggle="collapse">#i18n{participatoryideation.search.form.advanced.title}</a>
138
139 <div id="searchParameters" class="collapse dont-collapse-sm">
140
141 <div class="row">
142
143 <div class="col-md-3 col-xs-12">
144 <#-- Campaign-based search -->
145 <label class="select" for="campaign">
146 <select name="fq" id="campaign" onChange="searchArrond()" class="form-control <#if facet_campaign != "">selected</#if>">
147 <#if facet_campaign="">
148 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.campaign.label}</option>
149 <#else>
150 <option value="" >#i18n{participatoryideation.search.form.field.campaign.reset}</option>
151 </#if>
152
153 <option disabled="disabled">----</option>
154
155 <#if facets??>
156 <#list facets as facet>
157 <#if facet.name == "campaign_text">
158 <#list facet.values?sort as value>
159 <#if value.count != 0>
160 <#if facet_campaign == value.name>
161 <option value="campaign_text:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
162 <#else>
163 <option value="campaign_text:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
164 </#if>
165 </#if>
166 </#list>
167 </#if>
168 </#list>
169 </#if>
170 </select>
171 </label>
172 </div>
173
174 <div class="col-md-3 col-xs-12">
175 <#-- Location-based search -->
176 <label class="select" for="arrondissement">
177 <select name="fq" id="arrondissement" onChange="searchArrond()" class="form-control <#if arr != "">selected</#if>">
178 <#if arr=="">
179 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.location.label} </option>
180 <#else>
181 <option value="" >#i18n{participatoryideation.search.form.field.location.reset} </option>
182 </#if>
183
184 <option disabled="disabled">----</option>
185
186 <#if facets??>
187 <#list facets as facet>
188 <#if facet.name == "location_text">
189 <#list facet.values?sort as value>
190 <#if value.count != 0>
191 <#if arr == value.name>
192 <option value="location_text:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
193 <#else>
194 <option value="location_text:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
195 </#if>
196 </#if>
197 </#list>
198 </#if>
199 </#list>
200 </#if>
201
202 </select>
203 </label>
204 </div>
205
206 <div class="col-md-3 col-xs-12">
207 <#-- Theme-based search -->
208 <label class="select" for="theme">
209 <select name="fq" id="theme" onChange="searchArrond()" class="form-control <#if facet_theme != "">selected</#if>">
210 <#if facet_theme="">
211 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.theme.label}</option>
212 <#else>
213 <option value="">#i18n{participatoryideation.search.form.field.theme.reset}</option>
214 </#if>
215
216 <option disabled="disabled">----</option>
217
218 <#if facets??>
219 <#list facets as facet>
220 <#if facet.name == "code_theme_string">
221 <#list facet.values?sort as value>
222 <#if value.count != 0>
223 <#if facet_theme == value.name>
224 <option value="code_theme_string:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
225 <#else>
226 <option value="code_theme_string:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
227 </#if>
228 </#if>
229 </#list>
230 </#if>
231 </#list>
232 </#if>
233 </select>
234 </label>
235 </div>
236
237 <div class="col-md-3 col-xs-12">
238 <#-- SubmitterType-based search -->
239 <label class="select" for="submitter_type">
240 <select name="fq" id="submitter_type" onChange="searchArrond()" class="form-control <#if facet_submitter_type != "">selected</#if>">
241 <#if facet_submitter_type="">
242 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.submitter_type.label}</option>
243 <#else>
244 <option value="">#i18n{participatoryideation.search.form.field.submitter_type.reset}</option>
245 </#if>
246
247 <option disabled="disabled">----</option>
248
249 <#if facets??>
250 <#list facets as facet>
251 <#if facet.name == "code_submitter_type_string">
252 <#list facet.values?sort as value>
253 <#if value.count != 0>
254 <#if facet_submitter_type == value.name>
255 <option value="code_submitter_type_string:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
256 <#else>
257 <option value="code_submitter_type_string:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
258 </#if>
259 </#if>
260 </#list>
261 </#if>
262 </#list>
263 </#if>
264 </select>
265 </label>
266 </div>
267
268 </div>
269
270 <div class="row">
271
272 <div class="col-md-3 col-xs-12">
273 <#-- Status-based search -->
274 <label class="select" for="status">
275 <select name="fq" id="status" onChange="searchArrond()" class="form-control <#if facet_status != "">selected</#if>">
276 <#if facet_theme="">
277 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.status.label}</option>
278 <#else>
279 <option value="">#i18n{participatoryideation.search.form.field.status.reset}</option>
280 </#if>
281
282 <option disabled="disabled">----</option>
283
284 <#if facets??>
285 <#list facets as facet>
286 <#if facet.name == "statut_publique_project_text">
287 <#list facet.values?sort as value>
288 <#if value.count != 0>
289 <#if facet_status == value.name>
290 <option value="statut_publique_project_text:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
291 <#else>
292 <option value="statut_publique_project_text:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
293 </#if>
294 </#if>
295 </#list>
296 </#if>
297 </#list>
298 </#if>
299 </select>
300 </label>
301 </div>
302
303 <div class="col-md-3 col-xs-12">
304 <#-- QPop-based search -->
305 <label class="select" for="qpop">
306 <select name="fq" id="qpop" onChange="searchArrond()" class="form-control <#if facet_qpop != "">selected</#if>">
307 <#if facet_qpop="">
308 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.qpop.label}</option>
309 <#else>
310 <option value="">#i18n{participatoryideation.search.form.field.qpop.reset}</option>
311 </#if>
312
313 <option disabled="disabled">----</option>
314
315 <#if facets??>
316 <#list facets as facet>
317 <#if facet.name == "type_qpvqva_string">
318 <#list facet.values?sort as value>
319 <#if value.count != 0>
320 <#if facet_qpop == value.name>
321 <option value="type_qpvqva_string:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
322 <#else>
323 <option value="type_qpvqva_string:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
324 </#if>
325 </#if>
326 </#list>
327 </#if>
328 </#list>
329 </#if>
330 </select>
331 </label>
332 </div>
333
334 <div class="col-md-3 col-xs-12">
335 <label class="select" for="field4">
336 <select name="fq" id="field4" onChange="searchArrond()" class="form-control <#if facet_field4 != "">selected</#if>">
337 <#if facet_field4="">
338 <option value="" selected="selected">#i18n{participatoryideation.search.form.field.field4.label}</option>
339 <#else>
340 <option value="">#i18n{participatoryideation.search.form.field.field4.reset}</option>
341 </#if>
342
343 <option disabled="disabled">----</option>
344
345 <#if facets??>
346 <#list facets as facet>
347 <#if facet.name == "field4_string">
348 <#list facet.values?sort as value>
349 <#if value.count != 0>
350 <#if facet_field4 == value.name>
351 <option value="field4_string:${(value.name)!''}" selected="selected" >${(value.name)!''} (${(value.count)!''})</option>
352 <#else>
353 <option value="field4_string:${(value.name)!''}" >${(value.name)!''} (${(value.count)!''})</option>
354 </#if>
355 </#if>
356 </#list>
357 </#if>
358 </#list>
359 </#if>
360 </select>
361 </label>
362 </div>
363
364 <div class="col-md-3 col-xs-12">
365 </div>
366
367 </div>
368
369 </div>
370
371 </div>
372 </div>
373
374 <#-- Barre de tri et navigation -->
375 <div id="sub-search" class="container">
376 <div class="row">
377
378 <#-- Champs de tri -->
379 <div id="sub-search-left-panel" class="col-xs-6 col-sm-6 col-md-6">
380 <#if conf_user_query = "proposals_list">
381 <div id="sub-search-sorts">
382 <#if !(sort_name??) ><#assign sort_name="" ></#if>
383 <#if !(sort_order??)><#assign sort_order=""></#if>
384
385 <#-- if sort_list?? -->
386 <div class="form-group">
387 #i18n{participatoryideation.search.form.sort.title}
388 <label class="select" for="sort_name">
389 <select name="sort_name" id="sort_name" class="form-control" onChange="searchTri()" >
390 <#list sort_list as field>
391 <#if field.enableSort && (field.solrName="date" || field.solrName="titre" || field.solrName="nombre_de_votes_long")>
392 <#assign monTri = sort_name+"&sort_order="+sort_order>
393
394 <#if sort_name?ends_with("random") && ordre_aleatoire == "true" >
395 <option value="${number_random}_random" selected="selected" >#i18n{participatoryideation.search.form.sort.random.label}</option>
396 <#assign ordre_aleatoire= "false">
397 <#elseif ordre_aleatoire == "true" >
398 <option value="${number_random}_random">#i18n{participatoryideation.search.form.sort.random.label}</option> >
399 <#assign ordre_aleatoire= "false">
400 </#if>
401
402 <#if monTri==field.solrName+"&sort_order=asc" || monTri==field.solrName+"&sort_order=desc" >
403 <option value="${field.solrName}" selected="selected">${field.label} </option>
404 <#else>
405 <option value="${field.solrName}">${field.label} </option>
406 </#if>
407 </#if>
408 </#list>
409 <#assign monTri="&sort_name="+monTri />
410 </select>
411 </label>
412
413 <label class="select" for="sort_order">
414 <select name="sort_order" id="sort_order" class="form-control" onChange="searchTri()" >
415 <option value="asc" <#if sort_order?? && sort_order="asc">selected="selected"</#if> >#i18n{participatoryideation.search.form.sort.random.asc}</option>
416 <option value="desc" <#if sort_order?? && sort_order="desc">selected="selected"</#if>>#i18n{participatoryideation.search.form.sort.random.desc}</option>
417 </select>
418 </label>
419 </div>
420 <#-- /#if -->
421 </div>
422 </#if>
423 </div>
424
425 <#--Nombre d'items et icônes liste/carto -->
426 <div id="sub-search-right-panel" class="col-xs-6 col-sm-6 col-md-6">
427 <#if conf_user_query = "proposals_list">
428 <div id="sub-search-nbitems" class="">
429 ${i18n('participatoryideation.search.form.result.number', paginator.itemsCount)}
430 </div>
431 <div id="sub-search-switch">
432 <div class="form-group" >
433 <button id="button_map_list" class="btn btn-map-active" type="submit" alt="View map"><p>#i18n{participatoryideation.search.form.view.map}</p></button>
434 </div>
435 </div>
436 <#else>
437 <div id="sub-search-nbitems" class="">
438 ${i18n('participatoryideation.search.form.result.number', paginator.itemsCount)}
439 </div>
440 <div id="sub-search-switch">
441 <div class="form-group" >
442 <button id="button_list" class="btn btn-list-active" type="submit" alt="View list"><p>#i18n{participatoryideation.search.form.view.list}</p></button>
443 </div>
444 </div>
445 </#if>
446 </div>
447 </div>
448 </div>
449 </form>
450
451 </section>
452
453 <script type="text/javascript">
454
455 <#-- Dealing with list/map display buttons -->
456 <#if conf_user_query = "proposals_list">
457 <#assign other_view_code='proposals_map'>
458 <#else>
459 <#assign other_view_code='proposals_list'>
460 </#if>
461
462 $("#button_map_list").click( function(){
463 $("#form_conf_hidden").attr('value',"proposals_map");
464 });
465
466 $("#button_list").click( function(){
467 $("#form_conf_hidden").attr('value',"proposals_list");
468 });
469
470 function validateForm(form) {
471
472 var all_ok=true;
473 //From xss filter + lucene special characters
474 var forbidden_chars = "<>&|():~[]\\\"?*{}^+!";
475 $(form).find("input[type=text]").each(function(idx, elem) {
476 var error = false;
477 for (var i = 0; i < forbidden_chars.length; i++) {
478 if (!error && elem.value.indexOf(forbidden_chars.charAt(i)) != -1) {
479 error = true;
480 all_ok = false;
481 var parent = $(elem).parents(".form-group");
482 parent.addClass("has-error has-feedback");
483 var helpblock = $(parent).find(".help-txt");
484 helpblock.after("<p class=\"help-block\"><i class=\"fa fa-warning\"></i> Forbidden characters : " + forbidden_chars + "</p>");
485 helpblock.remove();
486 }
487 }
488 if (!error) {
489 var str = elem.value;
490 var prev_char = " ";
491 for(var i=0; i<str.length;i++) {
492 if (str[i] === "-" && prev_char === " ") {
493 error = true;
494 all_ok = false;
495 var parent = $(elem).parents(".form-group");
496 parent.addClass("has-error has-feedback");
497 var helpblock = $(parent).find(".help-txt");
498 helpblock.after("<p class=\"help-block\"><i class=\"fa fa-warning\"></i> Forbidden characters : " + forbidden_chars + "</p>");
499 helpblock.remove();
500 break;
501 }
502 prev_char=str[i];
503 }
504 }
505 });
506 if (!all_ok) {
507 $(form).find("button").removeAttr("disabled");
508 }
509 return all_ok;
510 }
511
512 function searchTheme (link) {
513 $("#type_search").val("theme");
514 $("#theme").val(link);
515 $("#search-prj-form").submit();
516 }
517
518 function getURLSubmit ()
519 {
520 var myquery = "";
521 checkComma();
522 if ($("#solr").val().trim()!="")
523 {
524 myquery = "&query=content:"+$("#solr").val();
525 }
526 var urltest = "${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name="+$("#sort").val()+myquery;
527 urltest += "<@EncodeFQ facets_list allParisCity allArrParisCity />";
528 return urltest;
529 }
530
531 $("#solr").bind("keypress", function (e) {
532 if (e.keyCode == 13) {
533 searchTri ();
534 }
535 });
536 function checkComma()
537 {
538 if ($("#solr").val().trim()!="")
539 {
540 var idTmp = $("#solr").val().trim();
541 if (idTmp.length > 2 && idTmp.substr(0,1)!="(" && idTmp.substr(idTmp.length-1)!=")")
542 $("#solr").val($("#solr").val());
543 }
544 }
545
546 function voteArrond (){
547 $("#type_search").val("arrondissement");
548 $("#type_search").val("arrondissement");
549 $("#arrondissement option").val("user_arrondissement")
550 checkComma();
551 $("#search-prj-form").submit();
552 }
553
554 function searchArrond () {
555 $("#type_search").val("arrondissement");
556 searchTri();
557 }
558
559 function searchBudget (budget) {
560 $("#sort_order option").val("budget_long&sort_order=asc");
561 $("#budget").val(budget);
562 searchTri();
563 }
564
565 function displayInMap() {
566 $("#form_conf_hidden").attr('value',"${other_view_code}");
567 }
568
569 function searchTri () {
570 $("#search-prj-form").find("button").attr("disabled", "disabled");
571 if ($("#arrondissement").val() == "all_arr")
572 {
573 window.location.href = getURLSubmit();
574 } else {
575 checkComma();
576 $("#search-prj-form").submit();
577 }
578 }
579
580 function getParameterByName(name) {
581 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
582 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
583 results = regex.exec(location.search);
584 return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
585 }
586
587 $(function(){
588 $("#adv-search").toggle();
589
590 var type_search = getParameterByName("type_search");
591 var order = getParameterByName("sort_name");
592
593 if (type_search == '' || type_search == 'simple' || type_search == 'theme') {
594 $("#type_search").val("simple");
595 } else {
596 $("#type_search").val("avancee");
597 }
598
599 $("select").change( function(){
600 searchArrond();
601 })
602
603 $("#search-prj-form").submit( function(){
604 return validateForm( $(this) );
605 })
606
607 });
608
609 </script>