In some cases, the property values that you want to include in the index (and therefore in the generated records) may not be the actual values used in the repository. For example, you may want to normalize values (e.g., index the color values Rose, Vermilion, Crimson, and Ruby all as Red, so they are all treated as the same dimension value). Or you may want to translate values into another language (e.g., index the color value Green as Vert, so when a customer searches for Vert, green items are returned).

To translate property values for indexing, you use the translate child element of the property element. The translate element has an input attribute for specifying a property value found in the repository, and an output attribute for specifying the value to translate this to in the output records. For example:

<property name="color" text-searchable="true" is-dimension="true">
  <translate input="Rose" output="Red"/>
  <translate input="Vermilion" output="Red"/>
  <translate input="Crimson" output="Red"/>
  <translate input="Ruby" output="Red"/>

The property element also has prefix and suffix child elements that you can use to append a text string before or after the output property values. For example, you can use the suffix element to add units to the property values:

<property name="length">
  <suffix value=" cm"/>

Note that the prefix and suffix values are concatenated to the property values exactly as specified, with no additional spaces. If you want spaces before the suffix string or after the prefix string, include the spaces in the value attribute, as in the example above.

You can use the prefix, suffix, and translate elements individually or in combination. The following example translates the size values S, M, and L, to “size small,” “size medium,” and “size large,” to make it easier for customers to search for specific sizes:

<property name="size" text-searchable="true" is-dimension="true">
  <prefix value="size "/>
  <translate input="S" output="small"/>
  <translate input="M" output="medium"/>
  <translate input="L" output="large"/>
Translating Based on Locale

The prefix, suffix, and translate elements all have optional locale attributes that allow you to specify different values for different locales. For example:

<property name="onSale" is-dimension="true">
  <translate locale="en_US" input="true" output="on sale"/>
  <translate locale="fr_FR" input="true" output="à la vente"/>
<property name="weight">
  <suffix locale="en_US" output=" grams"/>
  <suffix locale="fr_FR" output=" grammes"/>

When the records are generated, the IndexingOutputConfig component determines which tags to use based on the current locale. So if the locale is en_US, only the tags that specify that locale are applied.

Multilingual environments typically use the LocaleVariantProducer, which generates multiple records for each indexed item, one record for each locale specified in its locales array property. (See Using Variant Producers for more information.) If the value of the locales array is en_US,fr_FR, two sets of records are generated, one using the translate, prefix, and suffix tags whose locale is en_US, and one using the tags whose locale is fr_FR.

If a tag does not specify a locale, that tag is used as the default when the current locale does not match any of the other tags. In the following example, Rose is translated to Rouge if the locale is fr_FR, but is translated to Red for any other locale:

<property name="color" text-searchable="true" is-dimension="true">
  <translate input="Rose" output="Red"/>
  <translate locale="fr_FR" input="Rose" output="Rouge"/>

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved.

Legal Notices