In the project I’m working on I had a task to add custom facets to the search. Since version 5.0.a is the first one which supports faceted search the support for custom facets wasn’t there, at least I couldn’t find it. It seems that in further version of alfresco it is in place, but in the project I’m working on we had a strict requirement to use 5.0.a version. The solution I discovered is a bit “dirty” because instead of overriding the facet configuration component using aikau framework I just overwritten it. Another negative point is that it probably won’t work with further Alfresco versions, so you’ll need to update the code. But hopefully adding new facets would be easier in latest versions so this change won’t be to big. Let’s start! All the changes are done in share project.

Register extension

Create file: /web-extension/site-data/extensions/com/yourcomp/faceted-search-custom.xml file with following context:

      <id>EP faceted search</id>

Please note that <auto-deploy>true</auto-deploy> allows to automatically deploy created module instead of manually deploy it each time after you purge database.

##Extension implementation##

Next step is overwrite faceted-search.get.js. Copy it to web-extension/site-webscripts/com/yourcomp/pages/faceted-search/ and scroll down to ~120 line where the facets array is constructed. Feels free to remove some facets or to add new ones, in my case I added custom metadata field, which refers to the type of document:

    name: "alfresco/search/FacetFilters",
    config: {
      label: "Document Type",
      facetQName: "{}typeName.__.u",
      sortBy: "ALPHABETICALLY",
      hitThreshold: 1,
      minFilterValueLength: 5,
      maxFilters: 10,
      useHash: false

To check the config parameters refer to the documentation: FacetFilters config parameters.

In my case the document type name is several words split by space. To make solr search for the whole phrase and create whole prhase facet you need to add this part .__.u to the facet Qname. And also make sure that tokenised in the content model is set to false or both, so that the string is not tokenised before being indexed:

<property name="ef:typeName">
  <index enabled="true">