Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracted redundant TextLine and ISBN SearchField into a common base #422

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
56 changes: 56 additions & 0 deletions src/lib/FieldType/BaseSingleTextLineSearchField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* @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;

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;

abstract class BaseSingleTextLineSearchField implements Indexable
{
/**
* @return \Ibexa\Contracts\Core\Search\Field[]
*/
public function getIndexData(Field $field, FieldDefinition $fieldDefinition): array
{
return [
new Search\Field(
'value',
$field->value->data,
new Search\FieldType\StringField()
),
new Search\Field(
'fulltext',
$field->value->data,
new Search\FieldType\FullTextField()
),
];
}

/**
* @return array<string, \Ibexa\Contracts\Core\Search\FieldType>
*/
public function getIndexDefinition(): array
{
return [
'value' => new Search\FieldType\StringField(),
];
}

public function getDefaultMatchField(): string
{
return 'value';
}

public function getDefaultSortField(): string
{
return $this->getDefaultMatchField();
}
}
58 changes: 3 additions & 55 deletions src/lib/FieldType/ISBN/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
58 changes: 3 additions & 55 deletions src/lib/FieldType/TextLine/SearchField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading