Completed
Push — master ( ee9c7d...9819c1 )
by Rafael
14:45
created

SearchResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2015-2016 Timo Schmidt <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Grouping\Group;
29
30
/**
31
 * Proxy class for \Apache_Solr_Document to customize \Apache_Solr_Document without
32
 * changing the library code.
33
 *
34
 * Implements
35
 *
36
 * @author Timo Schmidt <[email protected]>
37
 */
38
class SearchResult extends \Apache_Solr_Document
39
{
40
41
    /**
42
     * @var bool
43
     */
44
    protected $throwExceptions = false;
45
46
    /**
47
     * @var SearchResult[]
48
     */
49
    protected $variants = [];
50
51
    /**
52
     * Indicates if an instance of this document is a variant (a sub document of another).
53
     *
54
     * @var bool
55
     */
56
    protected $isVariant = false;
57
58
    /**
59
     * References the parent document of the document is a variant.
60
     *
61
     * @var null
62
     */
63
    protected $variantParent = null;
64
65
    /**
66
     * @var Group
67
     */
68
    protected $group = null;
69
70
    /**
71
     * @param \Apache_Solr_Document $document
72
     * @param bool $throwExceptions
73
     */
74
    public function __construct(\Apache_Solr_Document $document, $throwExceptions = false)
75
    {
76
        $this->throwExceptions = false;
77
        $this->_documentBoost = $document->_documentBoost;
78
        $this->_fields = $document->_fields;
79
        $this->_fieldBoosts = $document->_fieldBoosts;
80
    }
81
82
    /**
83
     * @param string $name
84
     * @param array $arguments
85
     * @throws \Exception
86
     * @throws \RuntimeException
87
     * @return string
88
     */
89
    public function __call($name, $arguments)
90
    {
91
        try {
92
            return parent::__call($name, $arguments);
93
        } catch (\RuntimeException $e) {
94
            if ($this->throwExceptions) {
95
                throw $e;
96
            }
97
        }
98
    }
99
100
    /**
101
     * @return Group
102
     */
103
    public function getGroup(): Group
104
    {
105
        return $this->group;
106
    }
107
108
    /**
109
     * @param Group $group
110
     */
111
    public function setGroup(Group $group)
112
    {
113
        $this->group = $group;
114
    }
115
116
    /**
117
     * @return SearchResult[]
118
     */
119
    public function getVariants()
120
    {
121
        return $this->variants;
122
    }
123
124
    /**
125
     * @param SearchResult $expandedResult
126
     */
127
    public function addVariant(SearchResult $expandedResult)
128
    {
129
        $this->variants[] = $expandedResult;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function getIsVariant()
136
    {
137
        return $this->isVariant;
138
    }
139
140
    /**
141
     * @param bool $isVariant
142
     */
143
    public function setIsVariant($isVariant)
144
    {
145
        $this->isVariant = $isVariant;
146
    }
147
148
    /**
149
     * @return null
150
     */
151
    public function getVariantParent()
152
    {
153
        return $this->variantParent;
154
    }
155
156
    /**
157
     * @param null $variantParent
158
     */
159
    public function setVariantParent($variantParent)
160
    {
161
        $this->variantParent = $variantParent;
162
    }
163
164
    /**
165
     * @return string
166
     */
167
    public function getContent()
168
    {
169
        return $this->_fields['content'];
170
    }
171
172
    /**
173
     * @return boolean
174
     */
175
    public function getIsElevated()
176
    {
177
        return $this->_fields['isElevated'];
178
    }
179
180
    /**
181
     * @return string
182
     */
183
    public function getType()
184
    {
185
        return $this->_fields['type'];
186
    }
187
188
    /**
189
     * @return integer
190
     */
191
    public function getId()
192
    {
193
        return $this->_fields['id'];
194
    }
195
196
    /**
197
     * @return float
198
     */
199
    public function getScore()
200
    {
201
        return $this->_fields['score'];
202
    }
203
204
    /**
205
     * @return string
206
     */
207
    public function getUrl()
208
    {
209
        return $this->_fields['url'];
210
    }
211
212
    /**
213
     * @return string
214
     */
215
    public function getTitle()
216
    {
217
        return $this->_fields['title'];
218
    }
219
}
220