From 8212df8d3c7865f0513bcba052c56c2fda816f60 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 21 Jun 2024 14:35:35 +0200 Subject: [PATCH] Extracted redundant TextLine and ISBN SearchField into a common base --- .../BaseSingleTextLineSearchField.php | 56 ++++++++++++++++++ src/lib/FieldType/ISBN/SearchField.php | 58 +------------------ src/lib/FieldType/TextLine/SearchField.php | 58 +------------------ 3 files changed, 62 insertions(+), 110 deletions(-) create mode 100644 src/lib/FieldType/BaseSingleTextLineSearchField.php diff --git a/src/lib/FieldType/BaseSingleTextLineSearchField.php b/src/lib/FieldType/BaseSingleTextLineSearchField.php new file mode 100644 index 0000000000..33f79c70c7 --- /dev/null +++ b/src/lib/FieldType/BaseSingleTextLineSearchField.php @@ -0,0 +1,56 @@ +value->data, + new Search\FieldType\StringField() + ), + new Search\Field( + 'fulltext', + $field->value->data, + new Search\FieldType\FullTextField() + ), + ]; + } + + /** + * @return array + */ + public function getIndexDefinition(): array + { + return [ + 'value' => new Search\FieldType\StringField(), + ]; + } + + public function getDefaultMatchField(): string + { + return 'value'; + } + + public function getDefaultSortField(): string + { + return $this->getDefaultMatchField(); + } +} diff --git a/src/lib/FieldType/ISBN/SearchField.php b/src/lib/FieldType/ISBN/SearchField.php index 01c4052bbc..350b5e7131 100644 --- a/src/lib/FieldType/ISBN/SearchField.php +++ b/src/lib/FieldType/ISBN/SearchField.php @@ -4,67 +4,15 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\ISBN; -use Ibexa\Contracts\Core\FieldType\Indexable; -use Ibexa\Contracts\Core\Persistence\Content\Field; -use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; -use Ibexa\Contracts\Core\Search; +use Ibexa\Core\FieldType\BaseSingleTextLineSearchField; /** * Indexable definition for ISBN field type. */ -class SearchField implements Indexable +class SearchField extends BaseSingleTextLineSearchField { - public function getIndexData(Field $field, FieldDefinition $fieldDefinition) - { - return [ - new Search\Field( - 'value', - $field->value->data, - new Search\FieldType\StringField() - ), - new Search\Field( - 'fulltext', - $field->value->data, - new Search\FieldType\FullTextField() - ), - ]; - } - - public function getIndexDefinition() - { - return [ - 'value' => new Search\FieldType\StringField(), - ]; - } - - /** - * Get name of the default field to be used for matching. - * - * As field types can index multiple fields (see MapLocation field type's - * implementation of this interface), this method is used to define default - * field for matching. Default field is typically used by Field criterion. - * - * @return string - */ - public function getDefaultMatchField() - { - return 'value'; - } - - /** - * Get name of the default field to be used for sorting. - * - * As field types can index multiple fields (see MapLocation field type's - * implementation of this interface), this method is used to define default - * field for sorting. Default field is typically used by Field sort clause. - * - * @return string - */ - public function getDefaultSortField() - { - return $this->getDefaultMatchField(); - } } diff --git a/src/lib/FieldType/TextLine/SearchField.php b/src/lib/FieldType/TextLine/SearchField.php index 5cfd1375f4..a020a0864d 100644 --- a/src/lib/FieldType/TextLine/SearchField.php +++ b/src/lib/FieldType/TextLine/SearchField.php @@ -4,67 +4,15 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Core\FieldType\TextLine; -use Ibexa\Contracts\Core\FieldType\Indexable; -use Ibexa\Contracts\Core\Persistence\Content\Field; -use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; -use Ibexa\Contracts\Core\Search; +use Ibexa\Core\FieldType\BaseSingleTextLineSearchField; /** * Indexable definition for TextLine field type. */ -class SearchField implements Indexable +class SearchField extends BaseSingleTextLineSearchField { - public function getIndexData(Field $field, FieldDefinition $fieldDefinition) - { - return [ - new Search\Field( - 'value', - $field->value->data, - new Search\FieldType\StringField() - ), - new Search\Field( - 'fulltext', - $field->value->data, - new Search\FieldType\FullTextField() - ), - ]; - } - - public function getIndexDefinition() - { - return [ - 'value' => new Search\FieldType\StringField(), - ]; - } - - /** - * Get name of the default field to be used for matching. - * - * As field types can index multiple fields (see MapLocation field type's - * implementation of this interface), this method is used to define default - * field for matching. Default field is typically used by Field criterion. - * - * @return string - */ - public function getDefaultMatchField() - { - return 'value'; - } - - /** - * Get name of the default field to be used for sorting. - * - * As field types can index multiple fields (see MapLocation field type's - * implementation of this interface), this method is used to define default - * field for sorting. Default field is typically used by Field sort clause. - * - * @return string - */ - public function getDefaultSortField() - { - return $this->getDefaultMatchField(); - } }