forked from ezsystems/ezpublish-kernel
/
SearchField.php
82 lines (75 loc) · 2.31 KB
/
SearchField.php
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
<?php
/**
* This file is part of the eZ Publish Kernel 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 eZ\Publish\Core\FieldType\Date;
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
use eZ\Publish\SPI\FieldType\Indexable;
use eZ\Publish\SPI\Search;
use DateTime;
/**
* Indexable definition for Date field type.
*/
class SearchField implements Indexable
{
/**
* Get index data for field for search backend.
*
* @param \eZ\Publish\SPI\Persistence\Content\Field $field
* @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDefinition
*
* @return \eZ\Publish\SPI\Search\Field[]
*/
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
{
$dateTime = new DateTime("@{$field->value->data['timestamp']}");
return array(
new Search\Field(
'value',
$dateTime->format('Y-m-d\\Z'),
new Search\FieldType\DateField()
),
);
}
/**
* Get index field types for search backend.
*
* @return \eZ\Publish\SPI\Search\FieldType[]
*/
public function getIndexDefinition()
{
return array(
'value' => new Search\FieldType\DateField(),
);
}
/**
* 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();
}
}