Configuring the Advanced Search Dialog Box
The Advanced Search dialog box is displayed after clicking on the button in the cockpit content browser. While the content browser searches only description or PK, the Advanced Search area enables users to perform search based on extended set of attributes. These extended attributes are configured in an XML file, but can also be adjusted during the application runtime.
For details on how to import XML configuration files into the SAP Commerce Cloud Cockpit, see Importing Cockpit Configuration.
Configuring the Advanced Search Dialog Box
Figure: The Advanced Search dialog box.
Select the Sticky check box to make the Advanced Search dialog box permanently visible. The Clear all button clears all search properties.
In the code example below some properties have the visible attribute set to false. These properties aren't be visible when a user opens the Advanced Search dialog box for the first time. After pressing the Edit button, the user can choose the properties to be used. This setting remains until logging out, or until the perspective is changed.
Example of an advanced search configuration file:
<advanced-search>
<group name="root" type="product">
<label lang="en">Root</label>
<label lang="de">Alles</label>
<group name="general">
<label lang="de">Allgemein</label>
<label lang="en">General</label>
<property qualifier="product.code"/>
<property qualifier="product.name"/>
<property qualifier="product.description"
visible="false" sort-enabled="false"/>
</group>
<group name="admin" visible="false">
<label lang="de">Verwaltung</label>
<label lang="en">Admin</label>
<property qualifier="item.pk"
visible="false" sort-enabled="false"/>
<property qualifier="item.modifiedtime"
visible="false" sort-enabled="false"/>
</group>
<group name="dummy">
<label lang="de">Dummy</label>
<label lang="en">Dummy</label>
<property qualifier="product.ean"
visible="false" sort-enabled="false"/>
<property qualifier="product.manufacturerName"
visible="false" sort-enabled="false"/>
<property qualifier="SampleClassification/1.0/cpu.core"
visible="false" sort-enabled="false"/>
<property qualifier="SampleClassification/1.0/cpu.fsbSpeed"
visible="false" sort-enabled="false"/>
<property qualifier="SampleClassification/1.0/cpu.clockSpeed"
visible="false" sort-enabled="false"/>
<property qualifier="product.unit"
visible="false" sort-enabled="false" />
<property qualifier="product.supercategories"
visible="false" sort-enabled="false" />
</group>
</group>
</advanced-search>
Search Editors and Conditions
There are search editors for text, date and number attributes.
They provide support for various operators and can be easily configured and extended.
The following screenshots show a text and a date editor with default condition set.
Figure: Default text conditions.
Figure: Default date conditions.
Configuring Editor's Default Entries
For each editor type, there is a set of default operators defined in the XXX cockpit-spring-editors.xml file.
They can be customized by overwriting the definition of the bean with the ID editorConditionConfiguration.
Snippet from yourcockpit-spring-editors.xml:
<bean id="editorConditionConfiguration" parent="myCockpitEditorConditionConfiguration" /> <bean id="myCockpitEditorConditionConfiguration" parent="defaultEditorConditionConfiguration" class="de.hybris.platform.cockpit.model.advancedsearch.config.impl.DefaultEditorConditionConfiguration" abstract="true"> <property name="defaultConditionsMap"> <map merge="true"> <entry key="TEXT" value="startswith,contains,equals,endswith,isempty"/> <entry key="INTEGER" value="equals,between,greater,less,isempty"/> <entry key="LONG" value="equals,between,greater,less,isempty"/> <entry key="DECIMAL" value="equals,between,greater,less,isempty"/> <entry key="DATE" value="equals,between,isempty,today,tomorrow,thisweek,lastweek,thismonth,lastmonth"/> </map> </property>
Conditions are referenced by their operator qualifiers.
The list of available conditions is defined in cockpit-spring-editors.xml and but may be changed in one of the subsequent cockpit extensions in the inheritance tree.
Configuring an Editor for a Particular Attribute
It is possible to change the list of displayed conditions for a particular attribute in the advanced search configuration file.
There are three different modes for manipulating the default condition list:
- Append - the defined conditions are appended to the default list
- Replace - only the defined conditions are used, it can also be used to rearrange the order
- Exclude - the defined conditions are removed from the default list
In the append mode, you can also specify the index where to insert the condition in the default list.
The following screenshot shows a text search editor for product.code with additional between operator at the second position.
The configuration looks as follows:
<property qualifier="product.code" sort-enabled="true"> <conditions mode="append"> <condition operator="between" index="1"/> </conditions> </property>
Shortcuts
Shortcuts are simple links to existing conditions with prefilled values and can be used for frequently used condition values for an attribute. The following example shows how to configure a shortcut for the "between" operator for type text with prefilled values 1 and 10.
<condition operator="between" index="2"> <label lang="de">Zwischen 1 und 10</label> <label lang="en">Between 1 and 10</label> <values> <value type="java.lang.String">1</value> <value type="java.lang.String">10</value> </values> </condition>
Condition Translators: Adding Your Own Condition Entries
If you want to add a custom condition to the system, you first have to create a java class that implements the GenericQueryConditionTranslator interface, or the ConditionTranslator interface, if you don't use the GenericQuerySearchProvider. It is responsible for translating a SearchParameterValue into a GenericCondition.
Then you have to create a new ConditionTranslatorMapping bean in yourcockpit-spring-services.xml as follows:
<bean class="de.hybris.platform.cockpit.services.search.impl.ConditionTranslatorRegistry.ConditionTranslatorMapping"> <property name="attributeTypes"> <set> <value>TEXT</value> </set> </property> <property name="operatorQualifiers"> <set> <value>yourspecialoperator</value> </set> </property> <property name="translator" > <bean class="foo.bar.YourSpecialConditionTranslator"/> </property> </bean>
The properties attributeTypes and operatorQualifiers define for which types and operators your translator is valid and the translator property has to be set to your class.
Then you have to create a new condition entry bean and add it to the EditorConditionConfiguration in yourcockpit-spring-editors.xml and adjust the default conditions map, if wanted:
<bean id="myCockpitEditorConditionConfiguration" parent="defaultEditorConditionConfiguration" class="de.hybris.platform.cockpit.model.advancedsearch.config.impl.DefaultEditorConditionConfiguration" abstract="true"> <property name="defaultConditionsMap"> <map merge="true"> <entry key="TEXT" value="startswith,contains,equals,endswith,isempty,yourspecialoperator"/> </map> </property> <property name="conditions"> <list merge="true"> <ref bean="yourSpecialCondition"/> </list> </property> </bean> <bean id="yourSpecialCondition" scope="singleton" class="de.hybris.platform.cockpit.model.advancedsearch.config.impl.DefaultEditorConditionEntry"> <property name="validAttributeTypes" value="TEXT"/> <property name="operator" value="yourspecialoperator"/> <property name="i3Label" value="search.condition.yourspecialoperator" /> <property name="viewComponents" value="$TEXT"/> </bean>
The last property "viewComponents" in the above example defines the input fields and labels for your condition entry.
The following components are supported:
- $_TYPE: the input field related to the attribute type, it is very useful if your condition entry applies to more than one type
- $LABEL(...): a static localized label, defined by the i3-label-key in brackets
- $DATE, $DECIMAL, $INTEGER, $LONG, $TEXT: self-explaining.
Additionally, you can set the width of the component by trailing width definition in square brackets.
The following code shows how the between editor condition entry is defined:
<property name="viewComponents" value="$_TYPE[40px],$LABEL(search.condition.between.and)[30px],$_TYPE[40px]"/>