Tuesday 15 June 2010 5:20:10 am
Our per-year and per year/month data are now available, indexed in Solr. Left is only to build the facet navigation, the usual way :
{def $search_yearmonth=fetch( ezfind, search, hash( 'query' , '', 'facet', array( hash('field', 'billet/date/year', 'sort', 'alpha', 'limit', 20 ), hash('field', 'billet/date/yearmonth', 'sort', 'alpha', 'limit', 20 ) ), 'class_id', array('billet'), 'subtree_array', array(2) ))} {def $search_extras_year=$search_yearmonth['SearchExtras'].facet_fields[0].nameList|reverse} {def $search_extras_yearmonth=$search_yearmonth['SearchExtras'].facet_fields[1].nameList|reverse} {def $date_count = 0 $date_ts = 0} <li id="blog_block_10" class="colonne_block"> <h1>Archives par années :</h1> <ul class="list {$current_css}"> {foreach $search_extras_year as $facetID => $datevalue} {set $date_count = $search_yearmonth['SearchExtras'].facet_fields[0].countList[$facetID]} {set $date_ts = $datevalue|strtotime} <li><a href={concat('/Blogs/(year)/',$date_ts|datetime( 'custom', '%Y' ))|ezurl} title="Archives : {$date_ts|datetime( 'custom', '%Y' )} // {$date_count} Billet(s)">{$date_ts|datetime( 'custom', '%Y' )}</a></li> {/foreach} </ul> </li> <li id="blog_block_11" class="colonne_block"> <h1>Archives par mois / années :</h1> <ul class="list {$current_css}"> {foreach $search_extras_yearmonth as $facetID => $datevalue} {set $date_count = $search_yearmonth['SearchExtras'].facet_fields[1].countList[$facetID]} {set $date_ts = $datevalue|strtotime} <li><a href={concat('/Blogs/(year)/',$date_ts|datetime( 'custom', '%Y' ),'/(month)/',$date_ts|datetime( 'custom', '%n' ))|ezurl} title="Archives : {$date_ts|datetime( 'custom', '%F %Y' )} //{$date_count} Billet(s)">{$date_ts|datetime( 'custom', '%F %Y' )|upfirst}</a></li> {/foreach} </ul> </li> {undef $date_ts $date_count $search_yearmonth $search_extras_yearmonth}
Note :
The presented fetch is quite basic, for an easier understanding of the mechanism. This code needs to be elaborated to achieve the expected functional result (be able to use filter for instance). This is however not this tutorial's purpose, the official documentation already giving all hints for doing this.
2nd Note :
The 'sort', 'alpha' statement does not actually specify an alphabetical sort. It rather helps specifying that no 'count' sort should occur (number of items matching a given facet). In this case, Solr automatically uses an 'increasing' sort, based on its index and the datatype of the concerned field (this explains the usage of the reverse operator to get an 'increasing' list).