To specify a Map property, you use the item
element, set the is-multi
attribute to true
, and use the map-iteration-type
attribute to specify how to output the Map entries. If the Map values are primitives or Strings, set map-iteration-type
to wildcard
, as in this example:
<item property-name="personalData" is-multi="true" map-iteration-type="wildcard"> <properties> <property name="*" type="string"/> </properties> </item>
In the output, the Map keys are treated as subproperties of the Map property, and the Map values are treated as the values of these subproperties. All of the Map entries are included in the output. So, for example, the output from the definition file entry shown above might look like this:
<PROP NAME="personalData.firstName"> <PVAL>Fred</PVAL> </PROP> <PROP NAME="personalData.age"> <PVAL>37</PVAL> </PROP> <PROP NAME="personalData.height"> <PVAL>68</PVAL> </PROP>
If you want to output only a subset of the Map entries, explicitly specify the keys to include, rather than using the wildcard character (*
). For example:
<item property-name="personalData" is-multi="true" map-iteration-type="wildcard"> <properties> <property name="firstName" type="string" text-searchable="true"/> <property name="height" type="string"/> </properties> </item>
Maps of Repository Items
If the Map values are repository items, set map-iteration-type
to values
, and specify the properties of the repository item that you want to output. For example, suppose you want to index a productInfos
Map property whose keys are product IDs and whose values are productInfo
items:
<item property-name="productInfos" is-multi="true" map-iteration-type="values"> <properties> <property name="displayName" type="string" text-searchable="true"/> <property name="size" type="integer" is-dimension="true"/> </properties> </item>
The output will include displayName
and size
tags for each productInfo
item in the Map. In this case, the Map keys are ignored, the properties of the repository items are treated as subproperties of the Map property, and the values of the items are treated as the values of the subproperties. The output looks like this:
<PROP NAME="productInfos.displayName"> <PVAL>Funny Hat</PVAL> </PROP> <PROP NAME="productInfos.size"> <PVAL>8</PVAL> </PROP> <PROP NAME="productInfos.displayName"> <PVAL>Clown Shoes</PVAL> </PROP> <PROP NAME="productInfos.size"> <PVAL>14</PVAL> </PROP>