-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathContentDocumentTranslatedContentNameField.php
More file actions
96 lines (85 loc) · 2.93 KB
/
ContentDocumentTranslatedContentNameField.php
File metadata and controls
96 lines (85 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* This file is part of the eZ Platform Solr Search Engine package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\EzPlatformSolrSearchEngine\FieldMapper\ContentTranslationFieldMapper;
use EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider;
use EzSystems\EzPlatformSolrSearchEngine\FieldMapper\ContentTranslationFieldMapper;
use eZ\Publish\SPI\Persistence\Content;
use eZ\Publish\SPI\Persistence\Content\Type\Handler as ContentTypeHandler;
use eZ\Publish\SPI\Search\Field;
use eZ\Publish\SPI\Search\FieldType;
/**
* Maps Content fulltext fields to Content document.
*/
class ContentDocumentTranslatedContentNameField extends ContentTranslationFieldMapper
{
/**
* Field name, untyped.
*
* @var string
*/
private static $fieldName = 'meta_content__name';
/**
* @var \eZ\Publish\SPI\Persistence\Content\Type\Handler
*/
protected $contentTypeHandler;
/**
* @var \EzSystems\EzPlatformSolrSearchEngine\FieldMapper\BoostFactorProvider
*/
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,
$invalidCharactersPattern
) {
$this->contentTypeHandler = $contentTypeHandler;
$this->boostFactorProvider = $boostFactorProvider;
$this->invalidCharactersPattern = $invalidCharactersPattern;
}
public function accept(Content $content, $languageCode)
{
return true;
}
public function mapFields(Content $content, $languageCode)
{
if (!isset($content->versionInfo->names[$languageCode])) {
return [];
}
$contentName = preg_replace($this->invalidCharactersPattern, '', $content->versionInfo->names[$languageCode]);
$contentType = $this->contentTypeHandler->load(
$content->versionInfo->contentInfo->contentTypeId
);
return [
new Field(
self::$fieldName,
$contentName,
new FieldType\StringField()
),
new Field(
self::$fieldName,
$contentName,
new FieldType\TextField(
[
'boost' => $this->boostFactorProvider->getContentMetaFieldBoostFactor(
$contentType,
'name'
),
]
)
),
];
}
}