Mapping Targets
Mapping Targets
Mapping targets were introduced in Sitecore 7.0 Update-1 as a breaking change. They were added as a parameter to the method MapDocumentFieldsToType
inside the AbstractFieldNameTranslator
class. Mapping targets specify how the fields retrieved from the index should be mapped on the C# object. Currently, three mapping targets exist:
-
Indexer
will map the index fields directly onto the C# object indexer (for example,airport["City"] = indexField;
). -
Properties
will map the index fields directly onto the C# object properties (for example,airport.City = indexField;
). -
Anything
will simply map the index fields on the C# object indexer and its properties.
Coveo for Sitecore ignores the MappingTargetType
parameter and, instead, maps the fields to the C# object indexer and its properties, as depicted by the Anything
mapping target type. There’s no significant performance gain in mapping the index fields only on the indexer or the properties. Therefore, both targets are always mapped. Furthermore, mapping targets are only specified in the document mapping phase. Developers using the Solr, Lucene, or Coveo for Sitecore search providers can’t configure this value. The mapping targets can only be modified within the search provider itself.
A possible use case for discriminating the mapping targets inside a generic Search Provider would be to have a different naming convention for properties and indexer values. For example, a field with special characters such as #OfAirplanes in the index could be mapped to the property airport.NumberOfAirplanes
(since property names starting with the symbol # aren’t supported in C#), but mapped to the indexer airport["#OfAirplanes"]
. However, Coveo for Sitecore only supports alphanumerical names inside its index, therefore making all the index fields valid property names. In this context, such a use case has no benefits.