Wednesday, September 21, 2016

Create and Add Filter Properties to Alfresco Faceted/Filtered Search

Alfresco added new search capabilities in version 5.0.  Integration with the Solr 4 search engine brought with it the ability to do faceted searches.  Later, in Alfresco 5.1, Alfresco also introduced a tool for visually creating an Alfresco content model.

In this blog post we will use new visual Alfresco modeling tools to configure faceted search: Model Manager and Search Manager.  We will use Model Manager to create an aspect with two properties.  Then we will use Search Manager to create filters based on those new properties that we can add to Alfresco faceted search.  No coding is needed and the task can be done in about 30 minutes to an hour.

Let's look first at the Model Manager in the Share.  You can find this in the Share Administration console.  We'll create a new model and assign a unique namespace and name.  This example has to do with faceted search, so we will call it facetedmodel and assign a prefix for the model definitions to be fsrch.


Within the newly defined model, we then can create a new aspect.  We will call it fsrch:testSearch.  When defining the aspect name in the form, the model namespace prefix is not used.


Note that in 5.1 I noticed some page refresh problems with the Model Manager.  When creating the aspect and property values I needed to occasionally force a page refresh of the browser by using Ctrl-F5.

We'll create two properties that as part of the new aspect: department and number.  Department is a text field that will be constrained to be one value from among a list of possible values.  For the indexing specification, we assign List of Values -- Whole Match.  Selecting this will allow us to use this property later for faceted search.




The second property that we create is called fsrch:number which is an integer.  By selecting the "Enhanced Search" indexing option, we will later be able to include this property for faceted search.


Now that our model with a single aspect that has two properties has been defined, we can activate it so that it will be usable within our Alfresco instance.  In the next screenshot we can see the Activate option on the pulldown.


After doing that, we then see the green indicator on the row in the Model Manager for the model that shows that it is active.


We can also specify how the properties of the aspect will appear on edit and view forms in Alfresco.
To do that, we go back to the top of the Model Manager and look at the definition page for the model.  There we can see the types and aspects that make up the model.  In the Actions pulldown next on the row for our aspect, select "Layout Designer"

Doing that will bring up a visual editing tool that can let you easily design how content model properties will be displayed within edit and view pages of Alfresco.

In this case we lay out the two new properties to be displayed as a single new row for a form.  The selected area is a two column layout.  When the new aspect is applied to a standard content type item, the edit form for the item will display this row of our properties on the form.

Within the layout tool, we can specify labels that will appear next to each of the properties.


To test what we've done so far, we can find a content item that we've already uploaded and go into the details page for that item.  Here is a PDF file that was uploaded as standard content (cm:content).  On the details page, select Manage Aspects.  In the list of available assignable aspects, the new aspect is included.  Select that and add it to an assigned aspect for this content item.


When we look at the item where we assigned the aspect and select the "Edit Properties" action, we can see the new properties on the bottom of form.


And when looking on the bottom right of the item's details page, we can see the view form.  At the very bottom of the form are the two new properties that we just defined.
That's great.  Now we can create some items, assign the new aspect, and edit the new properties.  To speed up the task of assigning the aspect, it might be a good idea to create a rule on a folder that will automatically assign the new aspect as content is uploaded, although we won't show that here.

Now lets see how we can create faceted search filters on the search results page.  The search results page has a new option along the upper right side of the page called Search Manager.

On the Search Manager page we can define new filters for faceted search.  Click on Create New Filter.


Fill in the new filter dialog the information for the new department property.


Then, similarly, fill in information about the new property called number


Save both of these new filters.  Then on the Manage Search page notice that on the left there are arrows that allow you to position where the filter will appear in the faceted search panel.  We can position the new filters to appear prominently on top.


Now, execute a query and go to the search results page.  You will see something like the following.


The two new filters show on the left.  The current results are filtered by the Department called Engineering.

If you want to learn more about the Model Manager and the Search Manager, see these pages in the online Alfresco documentation:





3 comments:

  1. Hi, thanks for this great tutorial. But the "Enhanced Search" indexing option is not available on my current Alfresco 5.2 CE. How to make my custom properties able to show on adv search?

    Thanks,

    ReplyDelete
  2. The "Enhanced Search" option will be available for non-text data types which include int, long, float, double, date, datetime.
    Change the data type to one of those and the "Enhanced Search" option should become available.

    ReplyDelete
  3. This is great, thank you! Question - Instead of having a filter on the department aspect for engineering, can we have a search field that only search the fsrch:department aspect that we can manually enter Engineering?

    ReplyDelete