Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Upgrade from 5.4. Document Field Mappers

Upgrade from 5.4. Document Field Mappers
[Solr] Upgrade from 5.4. transform ExtendedEzfSolrDocumentFieldBase to Document Field Mappers.


I am on a migration from eZ Publish 5.4 to eZPLarform 1.13.

In my old site I had developed an implementation of ezfSolrDocumentFieldBase to index in solr specific business information to my products.

As I knew that I was going to have to do this migration, I decided to rely on the new stack as soon as possible in order to reduce the ‘disposable’ code as much as possible.

Here is my implementation of my ezfSolrDocumentFieldBase and its configuration.


 * The ProductIndexing.php class handles indexing and products in eZFind.
 * @see src/MyClient/FrontEndBundle/Helper/ProductHelper.php
 * @deprecated See ProductMapper.php
class ProductIndexing extends ezfSolrDocumentFieldBase
     * Get data to index, and field name to use.
     * @since ez find 2.2: indexed values to be context aware different fields may be used for searching, sorting and faceting
     * @return array Associative array with field name and field value.
     *               Field value can be an array.
     * @see ezfSolrDocumentFieldBase::getData()
    public function getData()
        $data = parent::getData();
        $contentClassAttribute = $this->ContentObjectAttribute->attribute( 'contentclass_attribute' );
        if ($contentClassAttribute->Identifier === 'product') {
            $content = $this->ContentObjectAttribute->object();
            $container = ezpKernel::instance()->getServiceContainer();
            $helper = $container->get( 'myclient.product_helper' );
            $r = $helper->getSolrIndexData($content->ID);
            foreach ($r as $k => $v) {
                $fieldName = 'subattr_'.$k.'____t';
                $data[$fieldName] = $v;
        return $data;



It worked very well. I could research the additional fields and they were taken into account in the text searches.

But that only works if I administer my products from the legacy BO.
If I want this information to be indexed when handling the product via the API or the new BO, do I have to make a Document Field Mappers?

Document Field Mappers

Here is my Document Field Mappers and its configuration.

namespace MyClient\FrontEndBundle\Mapper;
use MyClient\FrontEndBundle\Helper\ProductHelper;
use EzSystems\EzPlatformSolrSearchEngine\FieldMapper\ContentFieldMapper;
use eZ\Publish\SPI\Persistence\Content\Handler as ContentHandler;
use eZ\Publish\SPI\Persistence\Content\Location\Handler as LocationHandler;
use eZ\Publish\SPI\Persistence\Content;
use eZ\Publish\SPI\Search;

class ProductMapper extends ContentFieldMapper
    protected $contentHandler;
    protected $locationHandler;
    protected $helper; // Product helper

    public function __construct(
        ContentHandler $contentHandler,
        LocationHandler $locationHandler,
        ProductHelper $helper
    ) {
        $this->contentHandler = $contentHandler;
        $this->locationHandler = $locationHandler;
        $this->helper = $helper;

    public function accept(Content $content)
        return $content->versionInfo->contentInfo->contentTypeId == 69;

    public function mapFields(Content $content)
        $l = $this->helper->getSolrIndexData($content->versionInfo->contentInfo->id);
        $return = [];
        foreach ($l as $k => $v) {
            $v = is_array($v) ? implode(', ', $v) : $v; // $v is an array... and must be a string... 
            $return[] = new Search\Field($k, $v, new Search\FieldType\StringField());
        return $return;
        class: MyClient\FrontEndBundle\Mapper\ProductMapper
            - '@ezpublish.spi.persistence.content_handler'
            - '@ezpublish.spi.persistence.location_handler'
            - '@myclient.product_helper'
            - {name: ezpublish.search.solr.field_mapper.content}

Is this the right step?

Because I do not find my values in SOLR.