Solr Facets in Alfresco: A Walkthrough
One of the cool new features released in Alfresco 4 was the integration of Solr to support search in the Alfresco repository. Solr is a fast, scalable open source search server built on top of Apache Lucene. In addition to providing performant full-text search, replication and distributed search, Solr also ships with a number of search features that will enhance the end user’s search experience, including faceted search (synonymous with faceted navigation, faceted query and faceted browsing).
The current release of Alfresco 4 enterprise does not fully support Solr’s faceted search capabilities, so I implemented a solution to manage and display facet fields in Share.
The focus of this blog is to illustrate the functionality of my implementation. Through the use of screenshots I will walk through the functionality to show you how facet fields are added to Alfresco so that they are displayed along with the search results in Share.
A new Facet Management page has been added to Share’s admin console. The Facet Management page allows administrators to create, edit and delete facet fields within Alfresco. It also gives administrators control over how and when the facets should be displayed.
It is possible to navigate to the Facet Management page by selecting More…|More… from the main menu at the top of the page in Share.
By selecting the Facet Manager menu item in the left and column, the Facet Management page will be displayed.
Adding Facet Fields to Alfresco
When the New Facet button in the top right hand corner of the Facet Manager page is selected a dialog window will be presented that contains a facet field form.
The form contains the following fields:
- Facet Field Type – Drop down list containing the four different types of facets to choose from: Content Type, Mime Type, Property or Date.
- Facet Name – Drop down list containing the facet field names for the chosen Facet Type.
- Display Name – Text field for the display name.
- Minimum Count – Number field for the minimum count required for a facet.
- Limit – Number field for the limit of facets to be displayed for a facet field.
- Repository Search – Checkbox to include/exclude a facet field for Repository searches.
- All Sites - Checkbox to include/exclude a facet for All Site searches.
- Select Sites – Multi select field to select the sites that the facet field should be displayed for.
Below I will show you how I add a facet field for Alfresco’s title property. The title is not a typical choice for a facet, but it is an easy choice for those who want to follow these instructions without a custom content model enabled. Normally you would choose properties that contain discrete values from a finite set, such as: Geography, Status, Category, Currency, Author, Type, etc.
When I select the Property option from the Facet Type drop down list, a request is sent to Alfresco to get a list of properties that can be used as facets. The list that is returned in the response from Alfresco is populated in the Field Name drop down on the form. This list will only contain fields that have a verbatim copy of the field’s value in the index and therefore are deemed to be suitable candidates for facets. Note that the fully-qualified name is shown to clearly differentiate and group the various model namespaces.
I shall enter the following values for the other fields on the form:
- The text ‘Location’ in the Display Name text field. (I know it’s really a title, but let’s keep it simple and use the title field for locational information).
- The value 1 in the Minimum Count field, to ensure that only facets with a count of 1 or higher are returned in the results.
- The value 20 in the Limit field, so that no more than 20 facets will be displayed for this facet field.
- Select the ixxus site for the facet field search scope, this means that this facet field will only be displayed for ixxus site searches and will not be displayed for any other site searches or repository searches. These ‘Search Scope’ values are a useful way of creating facet display profiles on a per-site basis if needed.
Once I have saved the title property facet field, I shall also add facet fields for Content Type and Mime Type by choosing them the from the Facet Type drop down.
Now I shall add one more facet, but this time I shall select ‘Date’ from the Facet Type drop down. The facet field form that is presented in the dialog window for a date field contains additional parameters to capture the date range facet parameters required by Solr.
The date facet form has the additional fields:
- Date Start - Date field that represents the date range facet start date.
- Date End – Date field that represents the date range facet end date.
- Date Gap Type – Drop down list that contains a list of the available date gap types: Day, Month and Year.
- Date Gap - Drop down list containing the date gap options for the chosen Date Gap Type.
The Date Gap Type has 3 options, Day, Month and Year. When a Date Gap Type is selected it determines what options are displayed in the Date Gap drop down.
Once the facet fields have been created the Facet Management page will list the facet fields along with actions to edit and delete the facets.
Now I have four facet fields added to Alfresco I shall execute some searches to see them in action.
The search results page in Share has been modified to display the facets in a column on the left hand side of the page. For each facet field returned in the search results the Display Name that was entered in the facet field form is displayed and the facets are listed below the display name. Each facet in the list is a clickable link.
I will now execute a search within the ixxus site that I know will return multiple results:
As you can see in the screen shot above the facet fields I created using the Facet Manager - Location (Title), Content Type, Mime Type and Created Date - are displayed along with the search results which contains 15 documents.
If I select facets from the list the search results will be filtered to reflect the facet selection. When a facet is selected a search request is executed with original search term and an additional filter query. If multiple facets are selected, multiple filter queries will be added to the search request.
In the screen shot below I have filtered the search results by selecting the facets to find all documents that have a Location of London, are Microsoft Word documents, and were created between 1st July 2012 and 31st August 2012:
Once a facet has been selected and the results have been filtered it is possible to return to the unfiltered search results by selecting the boxed grey cross next to a facet.
Facet Field Configuration
Now I shall go back to the Facet Manager and edit some of the configurations to change how the facets are displayed on the search results page, I shall make the following changes:
- Remove the Content Type facet from the ixxus search scope.
- Set the Limit to 2 for the Location facets.
- Set the Minimum Count to 3 for Mime Type facets.
- Change the Date Gap to 1 month instead of 2 months for the Created Date facets.
- Add the Content Type facets and Mime Type facets to the Repository search.
When I execute another search on the ixxus site, you can see in the screen shot above the changes I made via the Facet Manager are reflected in the facets that are returned on the search results page.
- The Content Type facets are no longer displayed.
- There are only two Location facets displayed.
- Mime Type facets only have a count of 3 and above.
- Created Date range facets have a gap of one month.
If I execute an All Sites search, no facets are displayed which is expected as I didn’t add any facet fields to the All Sites search scope. Note that if the ‘Lucene’ search sub-system is enabled and not ‘Solr’, this view of search results without the facets, will always be shown:
If I execute a Repository search only Content Type and Mime Type facets are displayed which is what I configured in the Facet Manager:
So there you have it, Faceted Search in Alfresco. An easy and configurable way to add facets to an Alfresco instance and display them on the search results page in Share.
Whilst this blog focused on the functionality, I plan to write a follow up blog where I will go under the hood and talk more about the implementation.