Wednesday, September 14, 2016

Alfresco Filtered Search – How to display facet values of a date filter as date buckets or ranges



Filtered or faceted search within Alfresco allows users to filter and customize their results by applying multiple filters to their search results in a navigational way. Filtered search breaks up search results into multiple categories and allows the user to drill down or further restrict their search results based on those filters.

You can configure filtered search either by using the configuration files or by using the Share Search Manager.

With the Search Manager you can see details of existing search filters and also create new filters. In the Search Manager you can quickly create your own custom filters with a wide range of options available.

Create a new filter that uses a date property to filter results; you will see that the facet values for this date filter are not grouped in date buckets or ranges. Instead the facet values for the date property are displayed based on the full time stamp. For example see the Release Date and Valid To Date filter values in the following screenshot.























If you want to display the facet values of a date filter as date buckets or ranges, similar to how facet values are displayed for Created and Modified dates then take a look at the date buckets display handler configuration in the “solr-facets-context.xml” file and configure a similar handler for your date filter.

Take a look at the following configuration for date buckets display handler in the solr-facets-context.xml file:

   <bean id="facet.dateFacetFields" class="org.springframework.beans.factory.config.SetFactoryBean">
      <property name="sourceSet">
         <set>
            <value>@{http://www.alfresco.org/model/content/1.0}created</value>
            <value>@{http://www.alfresco.org/model/content/1.0}modified</value>
         </set>
      </property>  
   </bean>

   <bean id="facet.dateBuckets" class="org.springframework.beans.factory.config.MapFactoryBean">
      <property name="sourceMap">
               <map>
                  <!-- Bucket => yesterday TO today -->
                  <entry key="[NOW/DAY-1DAY TO NOW/DAY+1DAY]" value="faceted-search.date.one-day.label" />
                  <!-- Bucket => Last week TO today -->
                  <entry key="[NOW/DAY-7DAYS TO NOW/DAY+1DAY]" value="faceted-search.date.one-week.label" />
                  <!--  Bucket => Last month TO today -->
                  <entry key="[NOW/DAY-1MONTH TO NOW/DAY+1DAY]" value="faceted-search.date.one-month.label" />
                  <!--  Bucket => Last 6 months TO today -->
                  <entry key="[NOW/DAY-6MONTHS TO NOW/DAY+1DAY]" value="faceted-search.date.six-months.label" />
                  <!--  Bucket => Last year TO today -->
                  <entry key="[NOW/DAY-1YEAR TO NOW/DAY+1DAY]" value="faceted-search.date.one-year.label" />
               </map>
      </property>
   </bean>

   <bean id="facet.dateBucketsDisplayHandler" class="org.alfresco.repo.search.impl.solr.facet.handler.DateBucketsDisplayHandler" parent="baseFacetLabelDisplayHandler" >
      <constructor-arg index="0">
         <ref bean="facet.dateFacetFields" />
      </constructor-arg>
      <constructor-arg index="1">
         <ref bean="facet.dateBuckets" />
      </constructor-arg>
   </bean>

After configuring a custom date buckets display handler similar to the one defined in “solr-facets-context.xml” file, the facet values of the date filter will be displayed as date buckets or ranges. For an example see the Release Date and Valid To Date filter values in the following screenshot.





2 comments:

  1. Thumbnails of .dwg files provided via Formtek's EDM Module.

    ReplyDelete
  2. Among the posts I've seen, this is the most useful post about Alfresco Filtered Search, and I appreciate your efforts, thank you so much.

    ReplyDelete