Skip to content

Commit 0b6ceef

Browse files
authored
Extracted redundant TextLine and ISBN SearchField into a common base (#422)
For more details see #422
1 parent 0561171 commit 0b6ceef

File tree

3 files changed

+62
-110
lines changed

3 files changed

+62
-110
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Core\FieldType;
10+
11+
use Ibexa\Contracts\Core\FieldType\Indexable;
12+
use Ibexa\Contracts\Core\Persistence\Content\Field;
13+
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
14+
use Ibexa\Contracts\Core\Search;
15+
16+
abstract class BaseSingleTextLineSearchField implements Indexable
17+
{
18+
/**
19+
* @return \Ibexa\Contracts\Core\Search\Field[]
20+
*/
21+
public function getIndexData(Field $field, FieldDefinition $fieldDefinition): array
22+
{
23+
return [
24+
new Search\Field(
25+
'value',
26+
$field->value->data,
27+
new Search\FieldType\StringField()
28+
),
29+
new Search\Field(
30+
'fulltext',
31+
$field->value->data,
32+
new Search\FieldType\FullTextField()
33+
),
34+
];
35+
}
36+
37+
/**
38+
* @return array<string, \Ibexa\Contracts\Core\Search\FieldType>
39+
*/
40+
public function getIndexDefinition(): array
41+
{
42+
return [
43+
'value' => new Search\FieldType\StringField(),
44+
];
45+
}
46+
47+
public function getDefaultMatchField(): string
48+
{
49+
return 'value';
50+
}
51+
52+
public function getDefaultSortField(): string
53+
{
54+
return $this->getDefaultMatchField();
55+
}
56+
}

src/lib/FieldType/ISBN/SearchField.php

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,15 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Core\FieldType\ISBN;
910

10-
use Ibexa\Contracts\Core\FieldType\Indexable;
11-
use Ibexa\Contracts\Core\Persistence\Content\Field;
12-
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
13-
use Ibexa\Contracts\Core\Search;
11+
use Ibexa\Core\FieldType\BaseSingleTextLineSearchField;
1412

1513
/**
1614
* Indexable definition for ISBN field type.
1715
*/
18-
class SearchField implements Indexable
16+
class SearchField extends BaseSingleTextLineSearchField
1917
{
20-
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
21-
{
22-
return [
23-
new Search\Field(
24-
'value',
25-
$field->value->data,
26-
new Search\FieldType\StringField()
27-
),
28-
new Search\Field(
29-
'fulltext',
30-
$field->value->data,
31-
new Search\FieldType\FullTextField()
32-
),
33-
];
34-
}
35-
36-
public function getIndexDefinition()
37-
{
38-
return [
39-
'value' => new Search\FieldType\StringField(),
40-
];
41-
}
42-
43-
/**
44-
* Get name of the default field to be used for matching.
45-
*
46-
* As field types can index multiple fields (see MapLocation field type's
47-
* implementation of this interface), this method is used to define default
48-
* field for matching. Default field is typically used by Field criterion.
49-
*
50-
* @return string
51-
*/
52-
public function getDefaultMatchField()
53-
{
54-
return 'value';
55-
}
56-
57-
/**
58-
* Get name of the default field to be used for sorting.
59-
*
60-
* As field types can index multiple fields (see MapLocation field type's
61-
* implementation of this interface), this method is used to define default
62-
* field for sorting. Default field is typically used by Field sort clause.
63-
*
64-
* @return string
65-
*/
66-
public function getDefaultSortField()
67-
{
68-
return $this->getDefaultMatchField();
69-
}
7018
}

src/lib/FieldType/TextLine/SearchField.php

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,15 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Core\FieldType\TextLine;
910

10-
use Ibexa\Contracts\Core\FieldType\Indexable;
11-
use Ibexa\Contracts\Core\Persistence\Content\Field;
12-
use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition;
13-
use Ibexa\Contracts\Core\Search;
11+
use Ibexa\Core\FieldType\BaseSingleTextLineSearchField;
1412

1513
/**
1614
* Indexable definition for TextLine field type.
1715
*/
18-
class SearchField implements Indexable
16+
class SearchField extends BaseSingleTextLineSearchField
1917
{
20-
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
21-
{
22-
return [
23-
new Search\Field(
24-
'value',
25-
$field->value->data,
26-
new Search\FieldType\StringField()
27-
),
28-
new Search\Field(
29-
'fulltext',
30-
$field->value->data,
31-
new Search\FieldType\FullTextField()
32-
),
33-
];
34-
}
35-
36-
public function getIndexDefinition()
37-
{
38-
return [
39-
'value' => new Search\FieldType\StringField(),
40-
];
41-
}
42-
43-
/**
44-
* Get name of the default field to be used for matching.
45-
*
46-
* As field types can index multiple fields (see MapLocation field type's
47-
* implementation of this interface), this method is used to define default
48-
* field for matching. Default field is typically used by Field criterion.
49-
*
50-
* @return string
51-
*/
52-
public function getDefaultMatchField()
53-
{
54-
return 'value';
55-
}
56-
57-
/**
58-
* Get name of the default field to be used for sorting.
59-
*
60-
* As field types can index multiple fields (see MapLocation field type's
61-
* implementation of this interface), this method is used to define default
62-
* field for sorting. Default field is typically used by Field sort clause.
63-
*
64-
* @return string
65-
*/
66-
public function getDefaultSortField()
67-
{
68-
return $this->getDefaultMatchField();
69-
}
7018
}

0 commit comments

Comments
 (0)