Skip to content

Commit

Permalink
Merge branch '1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 29, 2020
2 parents f4503e2 + 04bde0e commit 215c4ed
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,19 @@ protected function getSearchTargetValueOne()

protected function getValidSearchValueTwo()
{
return 'wyoming.knott@ez.no';
return 'wyoming.knott@o2.ru';
}

protected function getSearchTargetValueTwo()
{
// ensure case-insensitivity
return strtoupper($this->getValidSearchValueTwo());
}

protected function getFullTextIndexedFieldData()
{
return [
['holmes4@ez.no', 'wyoming.knott@o2.ru'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,11 @@ protected function getValidSearchValueTwo()
{
return '9780380448340';
}

protected function getFullTextIndexedFieldData()
{
return [
['9780099067504', '9780380448340'],
];
}
}
8 changes: 8 additions & 0 deletions eZ/Publish/Core/FieldType/EmailAddress/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
$field->value->data,
new Search\FieldType\StringField()
),
new Search\Field(
'fulltext',
$field->value->data,
new Search\FieldType\FullTextField([
'space_normalize',
'latin1_lowercase',
], false)
),
];
}

Expand Down
5 changes: 5 additions & 0 deletions eZ/Publish/Core/FieldType/ISBN/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
$field->value->data,
new Search\FieldType\StringField()
),
new Search\Field(
'fulltext',
$field->value->data,
new Search\FieldType\FullTextField()
),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ protected function getWordIdSubquery(QueryBuilder $query, string $string): strin
$wordExpressions[] = $this->getWordExpression($query, $token);
}

// Search for provided string itself as well
$wordExpressions[] = $this->getWordExpression($subQuery, $string);

$whereCondition = $subQuery->expr()->orX(...$wordExpressions);

// If stop word threshold is below 100%, make it part of $whereCondition
Expand Down
14 changes: 14 additions & 0 deletions eZ/Publish/Core/Search/Legacy/Content/FullTextValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ class FullTextValue extends ValueObject
* @var bool
*/
public $isMainAndAlwaysAvailable;

/**
* Array of rules to be used when transforming the value.
*
* @var array
*/
public $transformationRules;

/**
* Flag whether the value should be split by non-words.
*
* @var bool
*/
public $splitFlag;
}
48 changes: 22 additions & 26 deletions eZ/Publish/Core/Search/Legacy/Content/Mapper/FullTextMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use eZ\Publish\Core\Search\Legacy\Content\FullTextData;
use eZ\Publish\SPI\Persistence\Content;
use eZ\Publish\SPI\Persistence\Content\Type;
use eZ\Publish\SPI\Search\Field;
use eZ\Publish\SPI\Search\FieldType;
use eZ\Publish\SPI\Persistence\Content\Type\Handler as ContentTypeHandler;
use eZ\Publish\Core\Search\Legacy\Content\FullTextValue;
Expand Down Expand Up @@ -73,8 +74,10 @@ public function mapContent(Content $content)
* @param \eZ\Publish\SPI\Persistence\Content $content
*
* @return \eZ\Publish\Core\Search\Legacy\Content\FullTextValue[]
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
protected function getFullTextValues(Content $content)
protected function getFullTextValues(Content $content): array
{
$fullTextValues = [];
foreach ($content->fields as $field) {
Expand All @@ -85,10 +88,13 @@ protected function getFullTextValues(Content $content)
continue;
}

$value = $this->getFullTextFieldValue($field, $fieldDefinition);
if (empty($value)) {
$fullTextField = $this->extractFullTextField($field, $fieldDefinition);
if (null === $fullTextField || empty($fullTextField->value)) {
continue;
}
$fullTextValue = !is_array($fullTextField->value)
? $fullTextField->value
: implode(' ', $fullTextField->value);

$contentInfo = $content->versionInfo->contentInfo;
$fullTextValues[] = new FullTextValue(
Expand All @@ -97,41 +103,31 @@ protected function getFullTextValues(Content $content)
'fieldDefinitionId' => $field->fieldDefinitionId,
'fieldDefinitionIdentifier' => $fieldDefinition->identifier,
'languageCode' => $field->languageCode,
'value' => !is_array($value) ? $value : implode(' ', $value),
'value' => $fullTextValue,
'isMainAndAlwaysAvailable' => (
$field->languageCode === $contentInfo->mainLanguageCode && $contentInfo->alwaysAvailable
),
'transformationRules' => $fullTextField->type->transformationRules,
'splitFlag' => $fullTextField->type->splitFlag,
]
);
}

return $fullTextValues;
}

/**
* Get FullTextField value.
*
* @param Content\Field $field
* @param Type\FieldDefinition $fieldDefinition
*
* @return string
*/
private function getFullTextFieldValue(Content\Field $field, Type\FieldDefinition $fieldDefinition)
{
private function extractFullTextField(
Content\Field $field,
Type\FieldDefinition $fieldDefinition
): ?Field {
$fieldType = $this->fieldRegistry->getType($field->type);
$indexFields = $fieldType->getIndexData($field, $fieldDefinition);

// find value to be returned (stored in FullTextField)
$fullTextFieldValue = '';
foreach ($indexFields as $field) {
/** @var \eZ\Publish\SPI\Search\Field $field */
if ($field->type instanceof FieldType\FullTextField) {
$fullTextFieldValue = $field->value;
break;
$fullTextFields = array_filter(
$fieldType->getIndexData($field, $fieldDefinition),
static function ($indexField) {
return $indexField->type instanceof FieldType\FullTextField;
}
}
);

// some full text fields are stored as an array of strings
return !is_array($fullTextFieldValue) ? $fullTextFieldValue : implode(' ', $fullTextFieldValue);
return !empty($fullTextFields) ? array_values($fullTextFields)[0] : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,14 @@ public function index(FullTextData $fullTextData)
} else {
$integerValue = 0;
}
$text = $this->transformationProcessor->transform($fullTextValue->value, $this->fullTextSearchConfiguration['commands']);
$text = $this->transformationProcessor->transform(
$fullTextValue->value,
!empty($fullTextValue->transformationRules)
? $fullTextValue->transformationRules
: $this->fullTextSearchConfiguration['commands']
);
// split by non-words
$wordArray = preg_split('/\W/u', $text, -1, PREG_SPLIT_NO_EMPTY);
$wordArray = $fullTextValue->splitFlag ? preg_split('/\W/u', $text, -1, PREG_SPLIT_NO_EMPTY) : [$text];
foreach ($wordArray as $word) {
if (trim($word) === '') {
continue;
Expand Down
22 changes: 22 additions & 0 deletions eZ/Publish/SPI/Search/FieldType/FullTextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,26 @@ class FullTextField extends FieldType
* @var string
*/
protected $type = 'ez_fulltext';

/**
* Transformation rules to be used when transforming the given string.
*
* @var array
*/
public $transformationRules;

/**
* Flag whether the string should be split by non-words.
*
* @var bool
*/
public $splitFlag;

public function __construct(array $transformationRules = [], bool $splitFlag = true)
{
$this->transformationRules = $transformationRules;
$this->splitFlag = $splitFlag;

parent::__construct();
}
}

0 comments on commit 215c4ed

Please sign in to comment.