Alfresco Advanced Search forms and user selected Metadata values
This blog is a reflection on Seed IMs experience with configuring Alfresco Advanced Search for custom metadata so that only the metadata items for which a user has selected values will be included in the search. The Alfresco Forms Framework allows you to configure search forms to search for content based on metadata fields. This blog discusses considerations for metadata fields that use lists of items and also how to ensure that the search only includes a metadata field in the search criteria if a user has entered or selected a value for the field in the search form.
Searching based on List (Constraint) values
When configuring a search form, the standard control to use for a single valued metadata field holding a list of items is the selectone control. This presents the list as a dropdown for users to select a value. However, the behaviour of the selectone control is to auto-select the first value of the list when the custom search form is loaded. Therefore, that metadata field will be included in your search even if a user does not select a value.
In order to load the list without a value being automatically chosen, the selectmany control should be used. One of the features of this approach is that a user can select mulitple values to include in the search for the single value field. The selectmany control has a special search parameter called “mode” which allows you to configure the behaviour if more than one value is selected for during search.Options for mode are OR & AND. OR will ensure that search will return all documents containing any of the search values whereas AND will only return documents containing both values. An example on how to configure the display control for a metadata field containing a list of items is provided below. It uses OR as its mode:
<field id="seed:studyType" label-id="label.seed_studyType" set="study-properties" > <control template="/org/alfresco/components/form/controls/selectmany.ftl" > <control-param name="options">Laboratory Study,Tox and Ecotox, ...</control-param> <control-param name="size">7</control-param> <control-param name="mode">OR</control-param> </control> </field>
As a side note, we used the options parameter in this case to provide a list of values that the user can select. Also, the size parameter sets the number of values to display.
Optional inclusion of Number & Date metatadata fields in search
In order to ensure that Numbers and Dates are not included as search criteria in a search if no value is provided by the user the NumberRange and DateRange controls should be used.
See below for examples.
<field id="my:numberproperty"> <control template="/org/alfresco/components/form/controls/numberrange.ftl" /> </field> <field id="my:dateproperty"> <control template="/org/alfresco/components/form/controls/daterange.ftl" /> </field>
References:
https://wiki.alfresco.com/wiki/Share_Advanced_Search#Search_Form_Controls
https://issues.alfresco.com/jira/browse/ALF-13557