1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
7
|
|
|
* |
8
|
|
|
* @license GNU General Public License version 3 or later. |
9
|
|
|
* For the full copyright and license information, please read the |
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Common\Solr\SearchResult; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Highlight class for the 'dlf' extension. It keeps highlight for found search phrase. |
17
|
|
|
* |
18
|
|
|
* @package TYPO3 |
19
|
|
|
* @subpackage dlf |
20
|
|
|
* |
21
|
|
|
* @access public |
22
|
|
|
*/ |
23
|
|
|
class Highlight |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @access private |
28
|
|
|
* @var string The identifier in form 'w_h_x_y' |
29
|
|
|
*/ |
30
|
|
|
private string $id; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @access private |
34
|
|
|
* @var int The horizontal beginning position of found highlight |
35
|
|
|
*/ |
36
|
|
|
private int $xBeginPosition; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @access private |
40
|
|
|
* @var int The horizontal ending position of found highlight |
41
|
|
|
*/ |
42
|
|
|
private int $xEndPosition; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @access private |
46
|
|
|
* @var int The vertical beginning position of found highlight |
47
|
|
|
*/ |
48
|
|
|
private int $yBeginPosition; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @access private |
52
|
|
|
* @var int The vertical ending position of found highlight |
53
|
|
|
*/ |
54
|
|
|
private int $yEndPosition; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The constructor for highlight. |
58
|
|
|
* |
59
|
|
|
* @access public |
60
|
|
|
* |
61
|
|
|
* @param array $highlight: Array of found highlight properties |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function __construct(array $highlight) |
66
|
|
|
{ |
67
|
|
|
// there is also possibility to access parentRegionIdx |
68
|
|
|
// $this->parentRegionId = $highlight['parentRegionIdx']; |
69
|
|
|
$this->xBeginPosition = $highlight['ulx']; |
70
|
|
|
$this->xEndPosition = $highlight['lrx']; |
71
|
|
|
$this->yBeginPosition = $highlight['uly']; |
72
|
|
|
$this->yEndPosition = $highlight['lry']; |
73
|
|
|
$this->id = $this->xBeginPosition . '_' . $this->yBeginPosition; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get the highlight's identifier. |
78
|
|
|
* |
79
|
|
|
* @access public |
80
|
|
|
* |
81
|
|
|
* @return string The highlight's identifier |
82
|
|
|
*/ |
83
|
|
|
public function getId(): string |
84
|
|
|
{ |
85
|
|
|
return $this->id; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the highlight's horizontal beginning position. |
90
|
|
|
* |
91
|
|
|
* @access public |
92
|
|
|
* |
93
|
|
|
* @return int The highlight's horizontal beginning position |
94
|
|
|
*/ |
95
|
|
|
public function getXBeginPosition(): int |
96
|
|
|
{ |
97
|
|
|
return $this->xBeginPosition; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get the highlight's horizontal ending position. |
102
|
|
|
* |
103
|
|
|
* @access public |
104
|
|
|
* |
105
|
|
|
* @return int The highlight's horizontal ending position |
106
|
|
|
*/ |
107
|
|
|
public function getXEndPosition(): int |
108
|
|
|
{ |
109
|
|
|
return $this->xEndPosition; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get the highlight's vertical beginning position. |
114
|
|
|
* |
115
|
|
|
* @access public |
116
|
|
|
* |
117
|
|
|
* @return int The highlight's vertical beginning position |
118
|
|
|
*/ |
119
|
|
|
public function getYBeginPosition(): int |
120
|
|
|
{ |
121
|
|
|
return $this->yBeginPosition; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the highlight's vertical ending position. |
126
|
|
|
* |
127
|
|
|
* @access public |
128
|
|
|
* |
129
|
|
|
* @return int The highlight's vertical ending position |
130
|
|
|
*/ |
131
|
|
|
public function getYEndPosition(): int |
132
|
|
|
{ |
133
|
|
|
return $this->yEndPosition; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|