Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
ezpublish.solr.engine_factory.class: EzSystems\EzPlatformSolrSearchEngineBundle\ApiLoader\SolrEngineFactory
ezpublish.solr.boost_factor_provider_factory.class: EzSystems\EzPlatformSolrSearchEngineBundle\ApiLoader\BoostFactorProviderFactory
ez_search_engine_solr.default_connection: ~
ez_search_engine_solr.invalid_characters_pattern: "#\\x1b[[][^A-Za-z]*[A-Za-z]#"

services:
ezpublish.solr.engine_factory:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,30 @@ class BlockDocumentsBaseContentFields extends ContentFieldMapper
*/
protected $sectionHandler;

/**
* @var string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this (here and on the others):

Suggested change
* @var string
* @var string Pattern with special characters that should be stripped from field value due to Solr not accepting them.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'regexp pattern' ?

*/
private $invalidCharactersPattern;

/**
* @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $locationHandler
* @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler
* @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler $objectStateHandler
* @param \eZ\Publish\SPI\Persistence\Content\Section\Handler $sectionHandler
* @param string $invalidCharactersPattern
*/
public function __construct(
LocationHandler $locationHandler,
ContentTypeHandler $contentTypeHandler,
ObjectStateHandler $objectStateHandler,
SectionHandler $sectionHandler
SectionHandler $sectionHandler,
$invalidCharactersPattern
) {
$this->locationHandler = $locationHandler;
$this->contentTypeHandler = $contentTypeHandler;
$this->objectStateHandler = $objectStateHandler;
$this->sectionHandler = $sectionHandler;
$this->invalidCharactersPattern = $invalidCharactersPattern;
}

public function accept(Content $content)
Expand Down Expand Up @@ -104,7 +112,7 @@ public function mapFields(Content $content)
),
new Field(
'content_name',
$contentInfo->name,
preg_replace($this->invalidCharactersPattern, '', $contentInfo->name),
new FieldType\StringField()
),
new Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,30 @@ class BlockDocumentsContentFields extends ContentTranslationFieldMapper
*/
protected $boostFactorProvider;

/**
* @var string
*/
private $invalidCharactersPattern;

/**
* @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler
* @param \eZ\Publish\Core\Search\Common\FieldRegistry $fieldRegistry
* @param \eZ\Publish\Core\Search\Common\FieldNameGenerator $fieldNameGenerator
* @param \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider $boostFactorProvider
* @param string $invalidCharactersPattern
*/
public function __construct(
ContentTypeHandler $contentTypeHandler,
FieldRegistry $fieldRegistry,
FieldNameGenerator $fieldNameGenerator,
BoostFactorProvider $boostFactorProvider
BoostFactorProvider $boostFactorProvider,
$invalidCharactersPattern
) {
$this->contentTypeHandler = $contentTypeHandler;
$this->fieldRegistry = $fieldRegistry;
$this->fieldNameGenerator = $fieldNameGenerator;
$this->boostFactorProvider = $boostFactorProvider;
$this->invalidCharactersPattern = $invalidCharactersPattern;
}

public function accept(Content $content, $languageCode)
Expand Down Expand Up @@ -102,7 +110,7 @@ public function mapFields(Content $content, $languageCode)
$fieldDefinition->identifier,
$contentType->identifier
),
$indexField->value,
preg_replace($this->invalidCharactersPattern, '', $indexField->value),
$this->getIndexFieldType($contentType, $fieldDefinition, $indexField->type)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,30 @@ class ContentDocumentFulltextFields extends ContentTranslationFieldMapper
*/
protected $boostFactorProvider;

/**
* @var string
*/
private $invalidCharactersPattern;

/**
* @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler
* @param \eZ\Publish\Core\Search\Common\FieldRegistry $fieldRegistry
* @param \eZ\Publish\Core\Search\Common\FieldNameGenerator $fieldNameGenerator
* @param \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider $boostFactorProvider
* @param $invalidCharactersPattern
*/
public function __construct(
ContentTypeHandler $contentTypeHandler,
FieldRegistry $fieldRegistry,
FieldNameGenerator $fieldNameGenerator,
BoostFactorProvider $boostFactorProvider
BoostFactorProvider $boostFactorProvider,
$invalidCharactersPattern
) {
$this->contentTypeHandler = $contentTypeHandler;
$this->fieldRegistry = $fieldRegistry;
$this->fieldNameGenerator = $fieldNameGenerator;
$this->boostFactorProvider = $boostFactorProvider;
$this->invalidCharactersPattern = $invalidCharactersPattern;
}

public function accept(Content $content, $languageCode)
Expand Down Expand Up @@ -104,7 +112,7 @@ public function mapFields(Content $content, $languageCode)

$fields[] = new Field(
self::$fieldName,
$indexField->value,
preg_replace($this->invalidCharactersPattern, '', $indexField->value),
$this->getIndexFieldType($contentType)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,24 @@ class ContentDocumentTranslatedContentNameField extends ContentTranslationFieldM
*/
protected $boostFactorProvider;

/**
* @var string
*/
private $invalidCharactersPattern;

/**
* @param \eZ\Publish\SPI\Persistence\Content\Type\Handler $contentTypeHandler
* @param \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider $boostFactorProvider
* @param $invalidCharactersPattern
*/
public function __construct(
ContentTypeHandler $contentTypeHandler,
BoostFactorProvider $boostFactorProvider
BoostFactorProvider $boostFactorProvider,
$invalidCharactersPattern
) {
$this->contentTypeHandler = $contentTypeHandler;
$this->boostFactorProvider = $boostFactorProvider;
$this->invalidCharactersPattern = $invalidCharactersPattern;
}

public function accept(Content $content, $languageCode)
Expand All @@ -60,7 +68,7 @@ public function mapFields(Content $content, $languageCode)
return [];
}

$contentName = $content->versionInfo->names[$languageCode];
$contentName = preg_replace($this->invalidCharactersPattern, '', $content->versionInfo->names[$languageCode]);
$contentType = $this->contentTypeHandler->load(
$content->versionInfo->contentInfo->contentTypeId
);
Expand Down
4 changes: 4 additions & 0 deletions lib/Resources/config/container/solr/field_mappers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- '@ezpublish.spi.persistence.content_type_handler'
- '@ezpublish.spi.persistence.object_state_handler'
- '@ezpublish.spi.persistence.section_handler'
- '%ez_search_engine_solr.invalid_characters_pattern%'
tags:
- {name: ezpublish.search.solr.field_mapper.block}

Expand All @@ -26,6 +27,7 @@ services:
- '@ezpublish.search.common.field_registry'
- '@ezpublish.search.common.field_name_generator'
- '@ezpublish.search.solr.field_mapper.boost_factor_provider'
- '%ez_search_engine_solr.invalid_characters_pattern%'
tags:
- {name: ezpublish.search.solr.field_mapper.block_translation}

Expand Down Expand Up @@ -53,6 +55,7 @@ services:
- '@ezpublish.search.common.field_registry'
- '@ezpublish.search.common.field_name_generator'
- '@ezpublish.search.solr.field_mapper.boost_factor_provider'
- '%ez_search_engine_solr.invalid_characters_pattern%'
tags:
- {name: ezpublish.search.solr.field_mapper.content_translation}

Expand All @@ -61,6 +64,7 @@ services:
arguments:
- '@ezpublish.spi.persistence.content_type_handler'
- '@ezpublish.search.solr.field_mapper.boost_factor_provider'
- '%ez_search_engine_solr.invalid_characters_pattern%'
tags:
- {name: ezpublish.search.solr.field_mapper.content_translation}

Expand Down