Alfresco 5 supports a newer version of the SOLR search engine than previous Alfresco releases. With this new engine, live search and filtered search have been added to the product. Much like previous versions of Alfresco, a simple search box is provided in Alfresco Share to allow for quickly searching for documents. This simple search box now allows for retrieving live results for both document and people searches. When using this search box, a specific set of metadata fields are targeted by a default query template. This article describes how these metadata fields can be extended to search for additional properties, such as properties in a custom model.
The screen shot below provides an example of a Live Search from the search box in Alfresco Share:
By default, live search will search against the following fields:
- cm:name, cm:title, cm:description, TEXT, and TAG
Simple search uses the following fields by default:
- cm:name, cm:title, cm:description,ia:whatEvent, ia:descriptionEvent, lnk:title, lnk:description, TEXT, and TAG
Both of these searches can be customized to add additional metadata fields if needed. To add additional properties, the following files will need to be customized and set to override the out of the box files:
- live-search-docs.get.config.xml
- search.get.config.xml
In current versions of Alfresco, neither of these files are exploded out into the file system from the WAR file. However, both of these files can be extracted from the following JAR file:
- tomcat/webapps/alfresco/WEB-INF/lib/alfresco-remote-api-5.0.2.1.jar (the version number will vary with the Alfresco version installed)
The JAR file can be extracted using a tool such as 7-ZIP. Once the JAR has been extracted, both of the out of the box configuration files are in the following path:
- alfresco/templates/webscripts/org/alfresco/slingshot/search/
These files can now be modified to add additional metadata fields as needed. Once the files have been updated, they should be deployed to the ‘extensions’ directory so that they will override the out of the box configuration. If you are deploying your code as a custom AMP file, the files should target the following directory:
- tomcat/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search
For this article, we will provide an example of this using an example model that is provided as part of the Alfresco installation that resides in the following directory:
- /tomcat/shared/classes/alfresco/extension/
Remove “.sample” from the following two files, and the example model will be bootstrapped once Alfresco has been restarted:
- exampleModel.xml.sample
- example-model-context.xml.sample
This example model adds a type named “my:sop”, and it includes the field “my:authorisedBy”. For this example, we will add “my:authorisedBy” as a field in our list of metadata properties in both the live search and simple search query templates.
Before proceeding, update “share-config-custom.xml” to add the “my:sop” type as an available subtype of “cm:content”. Then, create some test content of type “my:sop”, and add some values to “my:authorisedBy”. For reference, “share-config-custom.xml” is in the following location:
- /tomcat/shared/classes/alfresco/web-extension/share-config-custom.xml
The following section can be modified to allow for changing the sub-typing “cm:content” to “my:sop”:
<types>
<type name=”cm:content”>
<subtype name=”my:sop”/>
</type>
<type name=”cm:folder”>
</type>
<type name=”trx:transferTarget”>
<subtype name=”trx:fileTransferTarget” />
</type>
</types>
To add the custom metadata property field “my:authorisedBy” to the query templates for both live search and simple search. Examples are provided below:
- live-search-docs.get.config.xml:
<search>
<default-operator>AND</default-operator>
<default-query-template>%
(cm:name cm:titlecm:description my:authorisedBy TEXT TAG)
</default-query-template>
</search>
- search.get.config.xml:
<search>
<default-operator>AND</default-operator>
<default-query-template>%
(cm:name cm:title cm:description my:authorisedBy
ia:whatEvent ia:descriptionEvent lnk:title
lnk:description TEXT TAG)
</default-query-template>
</search>
Once this has been done, searches in the simple search box will include the ‘my:authorisedBy’ property in the search. In the screen shot below, the “my:authorisedBy” property is the only field that contains the word “Fred” for the “my:sop” document “text.txt”. It will appear as a result in live search now that “my:authorisedBy” has been added to the query template:
Additional fields can be added as needed, and they will be targeted from simple and live searches. It is important to also note that the list of metadata fields in the query template can be different for the live search and simple search if required.