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:





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.





Sunday, September 11, 2016

Kerberos authentication is not working; now what?



Debugging Kerberos authentication should be approached in a two-step process. The first is to make sure the Active Directory Kerberos users are properly created and Kerberos is configured correctly. You will use the “klist” and “kinit” commands to verify the Kerberos setup. The second, is to login into your Alfresco instance with Kerberos set as the only authentication option in your Authentication Chain. If the login fails you should turn on Kerberos debugging. This breaks the debugging into two separate phases; #1) the Kerberos install/configuration on your Active Directory server and #2) your Alfresco configuration and edited configuration files.

Phase #1:

Verify that the Kerberos users are properly created and Kerberos is configured correctly.

cd /etc

klist -k httpredhat.keytab

Keytab name: FILE:httpredhat.keytab
KVNO Principal
---- --------------------------------------------------------------------------
   0 HTTP/redhat.formtek.local@FORMTEK.LOCAL
                                 
klist -k cifsredhat.keytab

Keytab name: FILE:cifsredhat.keytab
KVNO Principal
---- --------------------------------------------------------------------------
   0 CIFS/redhat.formtek.local@FORMTEK.LOCAL

kinit -k –V -t /etc/keys/cifsredhat.keytab "CIFS/redhat.formtek.local"

Authenticated to Kerberos v5 

kinit -k –V -t /etc/keys/httpredhat.keytab "HTTP/redhat.formtek.local"

Authenticated to Kerberos v5

Phase #2:

If Phase #1 is verified and returning the proper values but your Alfresco authentication login fails you can now debug Kerberos issues using the log4j properties in the alfresco.log file. The file is located in ‘<Alfresco_Home>/tomcat/webapps/alfresco/WEB-INF/classes’ and is named ‘log4j.properties’.

log4j.logger.org.alfresco.web.app.servlet.KerberosAuthenticationFilter=debug
log4j.logger.org.alfresco.repo.webdav.auth.KerberosAuthenticationFilter=debug
 
NOTE: Make sure you add this to the end of the file or verify that there is only a single instance of these entries. 

The following is a sample login output:

16:16:17,818 DEBUG [app.servlet.KerberosAuthenticationFilter] New Kerberos auth request from 192.168.1.90 (192.168.1.90:22350)
16:16:18,036 DEBUG [app.servlet.KerberosAuthenticationFilter] User user1 logged on via Kerberos