solr_search_results.html

 1   <#setting url_escaping_charset="UTF-8">
 2   
 3   <#if conf_user_query??>
 4   <#assign conf_query = "&conf=${conf_user_query}">
 5   <#else>
 6   <#assign conf_query = "">
 7   </#if>
 8   
 9   <#-- Encode facet queries -->
 10   <#macro EncodeFQ list_fq optionalParam="" optionalParamDate=false >
 11   <#assign encoded_facets_queries = "">
 12   <#list list_fq as facet>
 13           <#assign facet_url = facet?url>
 14           <#if !optionalParam?has_content>
 15                   <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+facet_url>
 16           <#else>
 17                   <#if optionalParam != facet_url && optionalParamDate == false>
 18                           <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+facet_url>
 19                   </#if>
 20                   <#if optionalParam != facet_url?url && optionalParamDate== true >
 21                           <#assign encoded_facets_queries = encoded_facets_queries+"&fq="+facet_url>
 22                   </#if>
 23           </#if>
 24   </#list>
 25   ${encoded_facets_queries}
 26   </#macro>
 27   <#if conf.extraMappingQuery>
 28     <script type="text/javascript">
 29         var loadresource = document.createElement('link');
 30         loadresource.setAttribute("rel", "stylesheet");
 31         loadresource.setAttribute("type", "text/css");
 32         loadresource.setAttribute("href", "js/plugins/leaflet/leaflet/leaflet.css");
 33         document.getElementsByTagName("head")[0].appendChild(loadresource);
 34   
 35         loadresource = document.createElement('link');
 36         loadresource.setAttribute("rel", "stylesheet");
 37         loadresource.setAttribute("type", "text/css");
 38         loadresource.setAttribute("href", "js/plugins/leaflet/leaflet/MarkerCluster.css");
 39         document.getElementsByTagName("head")[0].appendChild(loadresource);
 40   
 41         loadresource = document.createElement('link');
 42         loadresource.setAttribute("rel", "stylesheet");
 43         loadresource.setAttribute("type", "text/css");
 44         loadresource.setAttribute("href", "js/plugins/leaflet/leaflet/MarkerCluster.Default.css");
 45         document.getElementsByTagName("head")[0].appendChild(loadresource);
 46     </script>
 47   
 48     <script src = "js/plugins/leaflet/leaflet/leaflet.js"></script>
 49     <script src="js/plugins/leaflet/leaflet/leaflet.markercluster.js"></script>
 50   
 51     <script type="text/javascript">
 52     $(window).on('load', function () {
 53           var map = L.map('map').setView([48.85632, 2.33272], 12);
 54           var points = [
 55               <#list points as point>
 56               {
 57                   "type": "${point.type}",
 58                   "code": "${point.code}",
 59                   "id": "${point.id}",
 60                   "geojson": ${point.geojson}
 61               }<#if point_has_next>,</#if>
 62               </#list>
 63           ];
 64   
 65           // create the tile layer with correct attribution
 66           var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
 67           var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
 68           var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 16, attribution: osmAttrib}).addTo(map);
 69   
 70           var marker_clusters = {};
 71           var marker_icons = {};
 72   
 73           //Workardound https://github.com/Leaflet/Leaflet/issues/3696
 74           var defaultIcon = L.Icon.extend({
 75               options: {
 76                   iconSize: [25, 41],
 77                   iconAnchor: [12, 41],
 78                   popupAnchor: [1, -34],
 79                   shadowSize: [41, 41],
 80                   shadowUrl: L.Icon.Default.imagePath + '/marker-shadow.png'
 81               }
 82           });
 83           var greenIcon = new defaultIcon({
 84               iconUrl: L.Icon.Default.imagePath + '/marker-icon-green.png',
 85               iconRetinaUrl: L.Icon.Default.imagePath + '/marker-icon-green-2x.png',
 86           });
 87           var yellowIcon = new defaultIcon({
 88                iconUrl: L.Icon.Default.imagePath + '/marker-icon-yellow.png',
 89                iconRetinaUrl: L.Icon.Default.imagePath + '/marker-icon-yellow-2x.png'
 90           });
 91           var redIcon = new defaultIcon({
 92               iconUrl: L.Icon.Default.imagePath + '/marker-icon-red.png',
 93               iconRetinaUrl: L.Icon.Default.imagePath + '/marker-icon-red-2x.png'
 94           });
 95           var createGreenCluster = function (cluster) {
 96               var childCount = cluster.getChildCount();
 97               return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster marker-cluster-small', iconSize: new L.Point(40, 40) });
 98           };
 99           var createYellowCluster = function (cluster) {
 100               var childCount = cluster.getChildCount();
 101               return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster marker-cluster-medium', iconSize: new L.Point(40, 40) });
 102           };
 103           var createRedCluster = function (cluster) {
 104               var childCount = cluster.getChildCount();
 105               return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', className: 'marker-cluster marker-cluster-large', iconSize: new L.Point(40, 40) });
 106           };
 107   
 108           for (var i = 0; i < points.length; i++) {
 109               var markers = undefined;
 110               var icon = undefined;
 111               var layer = "";
 112               var popupContent = undefined;
 113   
 114               var properties = points[i]["geojson"]["properties"];
 115               if (typeof(properties) != 'undefined') {
 116                   layer = properties["layer"];
 117               }
 118               if (!layer) {
 119                   layer = points[i]["code"];
 120               }
 121               if (typeof(marker_clusters[layer]) != "undefined") {
 122                   markers = marker_clusters[layer];
 123                   icon    = marker_icons[layer];
 124               } else {
 125                   if (typeof(properties) != 'undefined' && typeof(properties["icon"]) != 'undefined') {
 126                       var clusterIconCreateFunction = undefined;
 127                       if (properties["icon"] == 'red' ) {
 128                           icon = redIcon;
 129                           clusterIconCreateFunction = createRedCluster;
 130                       } else if (properties["icon"] == 'green' ) {
 131                           icon = greenIcon;
 132                           clusterIconCreateFunction = createGreenCluster;
 133                       } else if (properties["icon"] == 'yellow' ) {
 134                           icon = yellowIcon;
 135                           clusterIconCreateFunction = createYellowCluster;
 136                       }
 137   
 138                       if (typeof(clusterIconCreateFunction) != 'undefined') {
 139                           markers = new L.MarkerClusterGroup({
 140                               iconCreateFunction: clusterIconCreateFunction
 141                           });
 142                       }
 143                   }
 144   
 145                   if (typeof(icon) == 'undefined') {
 146                       markers = new L.MarkerClusterGroup();
 147                       icon = new L.Icon.Default();
 148                   }
 149   
 150                   marker_clusters[layer] = markers;
 151                   marker_icons[layer] = icon;
 152               }
 153   
 154   			var marker;
 155               
 156               if ( points[i]["geojson"]["geometry"]["type"] == "Point" ) {
 157               	marker = L.marker([points[i]["geojson"]["geometry"]["coordinates"][1],points[i]["geojson"]["geometry"]["coordinates"][0]] ,{icon: icon});
 158               }
 159               else if ( points[i]["geojson"]["geometry"]["type"] == "Polygon" ) {
 160                   
 161               	var aPolygon = points[i]["geojson"]["geometry"]["coordinates"];
 162   	    		marker = L.polygon(aPolygon, {color: points[i]["colorPolygon"], weight: points[i]["weight"] } );
 163               }
 164               else if ( points[i]["geojson"]["geometry"]["type"] == "Polyline" ) {
 165                 	 var coordPolyline = points[i]["geojson"]["geometry"]["coordinates"];
 166                 	marker = L.polyline(coordPolyline );
 167               }
 168   
 169               if ( (typeof(properties) != 'undefined') && (typeof(properties["popupContent"]) != 'undefined') ) {
 170                   if (properties["popupContent"]) {
 171                       marker.bindPopup(properties["popupContent"])
 172                   }
 173               } else {
 174                   popupContent = "<p>Loading " + points[i]["type"] + " " + points[i]["id"] + " " + points[i]["code"] + "...</p>";
 175                   marker.bindPopup(popupContent)
 176                   marker.on('click', (function(point) {
 177                       return function(e) {
 178                           var properties = point["properties"];
 179                           var popup = e.target.getPopup();
 180                           var url;
 181                           if ( (typeof(properties) != 'undefined') && (typeof(properties["popupAjax"]) != 'undefined') ) {
 182                               url = properties["popupAjax"];
 183                           } else {
 184                               url = "rest/leaflet/popup/" + point["type"] + "/" + point["id"] + "/" + point["code"];
 185                           }
 186   
 187                           $.get(url).done(function(data) {
 188                               popup.setContent(data);
 189                               popup.update();
 190                           }).fail(function() {
 191                               map.closePopup();
 192                           });
 193                       };
 194                   })(points[i]));
 195               }
 196   
 197               markers.addLayer(marker);
 198           }
 199           for (var markers in marker_clusters) {
 200               if (marker_clusters.hasOwnProperty(markers)) {
 201                   map.addLayer(marker_clusters[markers]);
 202               }
 203           }
 204   
 205         var baseMaps = {
 206             "osm": osm
 207         };
 208         var overlayMaps = marker_clusters;
 209         // paramétrage et ajout du L.control.layers à la carte
 210         L.control.layers(baseMaps, overlayMaps).addTo(map);
 211     });
 212     </script>
 213   </#if>
 214   
 215   <div class="row">
 216   <#-- facets -->
 217   <div class="col-sm-3 well" >
 218   
 219       <#-- Historique -->
 220       <div id="histoique" class="portlet -lutece-border-radius append-bottom">
 221           <table>
 222               <tr>
 223                   <td>
 224                       <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}${conf_query}">#i18n{search.solr.display.result.raffinement.clear}</a>
 225                   </td>
 226               </tr>
 227           </table>
 228       </div>
 229   
 230       <#-- facet refining -->
 231       <div id="facets" class="portlet -lutece-border-radius append-bottom">
 232           <#-- facets field -->
 233           <#if facets??><#-- empty or null when no connection to server -->
 234           <#list facets as facet>
 235           <#if facet.values?? >
 236           <#-- when there is no result, facet is not null, but facet.values is -->
 237           <table>
 238               <th>
 239                   ${solr_fields[facet.name].label} 
 240               </th>
 241               <tr>
 242                   <td>
 243                       <ul>
 244                           <#list facet.values as count>
 245   				<#assign sh = "">
 246               			<#list historique as fh>
 247   					<#if fh.name = facet.name+":"+count.name>
 248   						<#assign sh = facet.name+":"+count.name>
 249   					</#if>
 250               			</#list>
 251   
 252                           <li>
 253    			<#if sh?has_content >
 254   							${count.name}(${count.count})
 255                               <a  class="glyphicon glyphicon-remove" href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}<@EncodeFQ facets_list sh?url />${conf_query}"></a>
 256               <#else>
 257                               <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}&facetlabel=${count.name}&facetname=${facet.name}&fq=${facet.name}:${count.name?url}<@EncodeFQ facets_list />${conf_query}">${count.name}(${count.count})</a>
 258   			</#if>
 259                           </li>
 260                           </#list>
 261                       </ul>
 262                   </td>
 263               </tr>
 264           </table>
 265           </#if>
 266           </#list>
 267           </#if>
 268   
 269           <#-- facets date refining -->
 270           <#if facets_date??>
 271           <#list facets_date as field>
 272           <#if field.counts??>
 273           <#-- when there is no result, facet is not null, but facet.counts is -->
 274           <table>
 275               <th>
 276                   ${solr_fields[field.name].label}
 277               </th>
 278               <tr>
 279                   <td>
 280                       <ul>
 281                           <#list field.counts as count>
 282                           <#if count.count != 0>
 283                           <li>
 284                               <#assign toDate = "${count.value}"?datetime("yyyy-MM-dd'T'HH:mm:ss'Z'")>
 285                               <#assign daterange = "${field.name}:[${count.value} TO ${count.value}${facetDateGap}]"?url>
 286                               <#assign toString = "${toDate?string('yyyy')}">
 287                                   <#assign sh = "">
 288                                   <#list historique as fh>
 289                                           <#if fh.name?url = daterange>
 290                                                   <#assign sh = daterange>
 291                                           </#if>
 292                                   </#list>
 293                           <#if sh?has_content >
 294                                   ${toString}(${count.count})
 295                               <a class="glyphicon glyphicon-remove" href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}<@EncodeFQ  facets_list sh?url true />${conf_query}"></a>
 296                           <#else>
 297                               <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}&facetlabel=${toString}&facetname=${field.name}&fq=${daterange}<@EncodeFQ  facets_list />${conf_query}">${toString}(${count.count})</a>
 298                           </#if>
 299                           </li>
 300                           </#if>
 301                           </#list>
 302                       </ul>
 303                   </td>
 304               </tr>
 305           </table>
 306           </#if>
 307           </#list>
 308           </#if>	
 309       </div>
 310   
 311       <#-- facets Intersection -->
 312       <#if facet_tree??>
 313       <div id="intersection" class="portlet -lutece-border-radius append-bottom">
 314           <#list facet_tree?keys as key>
 315           <table>
 316               <th>
 317                   <#assign field1= "${key}"?split(",")[0] >
 318                   <#assign field2= "${key}"?split(",")[1] >
 319                   ${solr_fields[field1].label} / ${solr_fields[field2].label}
 320               </th>
 321               <#list facet_tree[key] as facet>
 322               <#if facet.values??>
 323               <#-- when there is no result, facet is not null, but facet.values is -->
 324               <tr>
 325                   <td>
 326                       <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}&fq=${field1}:${facet.name?url}<@EncodeFQ  facets_list/>${conf_query}">${facet.name}</a>
 327                   </td>
 328               </tr>
 329               <tr>
 330                   <td>
 331                       <ul>
 332                           <#list facet.values as count>
 333                           <li>
 334                               <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}&query=${query?url}&fq=${field1}:${facet.name?url}&fq=${field2}:${count.name?url}<@EncodeFQ  facets_list/>${conf_query}">${count.name}(${count.count})</a>
 335                           </li>
 336                           </#list>
 337                       </ul>
 338                   </td>
 339               </tr>
 340               </#if>
 341               </#list>
 342           </table>
 343           </#list>
 344       </div>
 345       </#if>
 346   
 347       <#-- sort order -->
 348       <#if sort_list??>
 349       <div id="tri" class="portlet -lutece-border-radius append-bottom">
 350           <table>
 351               <th>
 352                   #i18n{search.solr.display.result.sort}
 353               </th>
 354               <#list sort_list as field>
 355               <#if field.enableSort>
 356               <tr>
 357                   <td>
 358                       <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&query=${query?url}<@EncodeFQ  facets_list />&sort_name=${field.solrName}&sort_order=desc${conf_query}">${field.label} desc</a>
 359                   </td>
 360               </tr>
 361               <tr>
 362                   <td>
 363                       <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&query=${query?url}<@EncodeFQ  facets_list />&sort_name=${field.solrName}&sort_order=asc${conf_query}">${field.label} asc</a>
 364                   </td>
 365               </tr>
 366               </#if>
 367               </#list>
 368           </table>
 369       </div>
 370       </#if>
 371   </div>
 372   
 373   <#-- results -->
 374   <div id="resultList" class="col-sm-6">
 375       <#-- new Search -->
 376       <div id="newSearch" class="append-bottom ">
 377   	<div class="well">
 378   		<form name="search" method="post" action="${fullUrl}">
 379   		    <div class="hide">
 380   		        <input type="hidden" name="page" value="search-solr" />
 381   		        <#if conf_user_query??>
 382   		        <input type="hidden" name="conf" value="${conf_user_query}" />
 383   		        </#if>
 384   		        <input type="hidden" name="sort_name" value="${sort_name!}" />
 385   		        <input type="hidden" name="sort_order" value="${sort_order!}" />
 386   		        <#if facets_list??>
 387   		        <#list facets_list as facet>
 388   		        <input type="hidden" name="fq" value="${facet}" />
 389   		        </#list>
 390   		        </#if>
 391   
 392   		    </div>
 393   		    <div style="text-align:center;">
 394   		        <input type="text" name="query" size="35" value="${query?if_exists}" id="solr" /> 
 395   			<span>
 396   		        	<input type="submit" value="#i18n{portal.search.search_results.buttonSearch}" />
 397   			</span>
 398   		    </div>
 399   	    </div>
 400           <#if conf.extraMappingQuery>
 401           <div id="map" style="height: 400px; width: 100%"></div>
 402           </#if>
 403               <div>
 404                   <#-- Number of documents per page selector -->
 405                   #i18n{portal.search.search_results.labelNbDocsPerPage}: 
 406                   <@NbItemsPerPageSelectorCombo nb_items_per_page?string />
 407               </div>
 408           </form>
 409       </div>
 410       <div id="resultList2" class="portlet -lutece-border-radius">
 411           <legend>#i18n{portal.search.search_results.title}</legend>
 412           <#if error?has_content>
 413           <div class="error">${error}</div>
 414           </#if>
 415           <div>#i18n{portal.search.search_results.labelResultsCount} : <strong>${paginator.itemsCount}</strong></div>
 416           
 417   
 418           <#-- spellChecker -->
 419   		<#if suggestion?has_content>
 420           <div id="spellchecker">
 421             #i18n{search.solr.display.result.spellchecker}
 422             <#list suggestion as sugg>
 423                   <#assign newQuery="" >
 424                   <a href="${fullUrl}?page=search-solr&items_per_page=${nb_items_per_page}&query=${sugg.getCollationQueryString()?url}<@EncodeFQ  facets_list  />${conf_query}">${sugg.getCollationQueryString()}</a>
 425           </#list>
 426           </div>
 427           </#if>
 428   
 429   
 430           <div>&nbsp;</div>
 431           <div id="pagination" class="pagination">
 432               <p>
 433                   <@pagination paginator=paginator />
 434               </p>
 435           </div>
 436   
 437           <div id="resultItems" class="">
 438               <div>
 439                   <#list results_list as result>
 440                   <div id="item" >
 441                       <!-- <img src="document?id=${result.id}&id_attribute=79" style="float:left; margin-right:12px"/> -->
 442                       <div style="font-weight:bold; font-size:1.2em"><a href="${result.url}&terms=${query?url}&items_per_page=${nb_items_per_page}&sort_name=${sort_name!}&sort_order=${sort_order!}<@EncodeFQ  facets_list />">${result.title}</a></div>
 443   
 444                       <#if result.summary??>${(result.highlight.map["summary"][0])!result.summary}</#if>
 445                       <#if result.highlight??>
 446                       <#-- get a extract from the "content" field where there is one (or more) of the searched words -->
 447                       <#if result.highlight.map["content"]??>
 448                       #i18n{search.solr.display.result.summary.extract} : 
 449                       <#list result.highlight.map["content"] as extrait>
 450                       ${extrait}
 451                       </#list>
 452                       </#if>
 453                       </#if>
 454                       <br />
 455                       <div style="text-align:right; font-size:0.8em;" ><#if result.date?has_content>${result.date?date}</#if></div>
 456                   </div>
 457   		<hr/>
 458                   </#list>
 459               </div>
 460           </div>
 461       </div>
 462       <div>#i18n{portal.search.search_results.labelResultsRange} : <strong>${paginator.rangeMin} - ${paginator.rangeMax}</strong></div>
 463   </div>
 464   </div>
 465   <#-- Freemarker macros -->
 466   
 467   <#-- Number of items per page selector - Combo Box implementation -->
 468   <#macro NbItemsPerPageSelectorCombo nb_items_per_page>
 469   <select name="items_per_page">
 470       <#list [ "10" , "20" , "50" , "100" ] as nb>
 471       <#if nb_items_per_page = nb >
 472       <option selected="selected" value="${nb}">${nb}</option>
 473       <#else>
 474       <option value="${nb}">${nb}</option>
 475       </#if>
 476       </#list>
 477   </select>
 478   </#macro>
 479   
 480   <#-- Number of items per page selector - Radio List implementation -->
 481   <#macro NbItemsPerPageSelectorRadioList nb_items_per_page>
 482   <#list [ "5" , "10" , "20" , "50" ] as nb>
 483   <#if nb = nb_items_per_page > 
 484   <input value="${nb}" id="items_per_page${nb}" name="items_per_page" class="radio" type="radio" checked /><label for="items_per_page${nb}">${nb}</label>
 485   <#else>
 486   <input value="${nb}" id="items_per_page${nb}" name="items_per_page" class="radio" type="radio" /><label for="items_per_page${nb}">${nb}</label>
 487   </#if>
 488   </#list>
 489   </#macro>
 490   
 491   <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
 492     <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
 493     <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
 494   
 495   
 496   <script>
 497   
 498   $(function() {
 499     $('#solr').autocomplete({
 500       source: function(request, response) {
 501         $.ajax({
 502           url: '@base_url@servlet/plugins/SolrSuggest',
 503           dataType: 'jsonp',
 504   minLength: 3,
 505   data: {
 506   q: request.term,
 507   },
 508   success: function(data) {
 509   var formattedResponse = $.map(data.response.docs, function (item) {
 510   return {
 511   label: item.title,
 512   value: item.title,
 513   };
 514   });
 515   response( formattedResponse );
 516   }
 517   });
 518   },
 519   
 520   });
 521   });
 522   
 523   
 524   </script>