1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the SubtreeIn criterion visitor class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Search\Elasticsearch\Content\Location\CriterionVisitor; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher as Dispatcher; |
14
|
|
|
use eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Visits the Subtree criterion. |
20
|
|
|
*/ |
21
|
|
|
class SubtreeIn extends CriterionVisitor |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Check if visitor is applicable to current criterion. |
25
|
|
|
* |
26
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
27
|
|
|
* |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public function canVisit(Criterion $criterion) |
31
|
|
|
{ |
32
|
|
|
return |
33
|
|
|
$criterion instanceof Criterion\Subtree && |
34
|
|
|
( |
35
|
|
|
($criterion->operator ?: Operator::IN) === Operator::IN || |
36
|
|
|
$criterion->operator === Operator::EQ |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns condition common for filter and query contexts. |
42
|
|
|
* |
43
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
protected function getCondition(Criterion $criterion) |
48
|
|
|
{ |
49
|
|
|
$filters = array(); |
50
|
|
|
|
51
|
|
|
foreach ($criterion->value as $value) { |
|
|
|
|
52
|
|
|
$filters[] = array( |
53
|
|
|
'prefix' => array( |
54
|
|
|
'path_string_id' => $value, |
55
|
|
|
), |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $filters; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Map field value to a proper Elasticsearch representation. |
64
|
|
|
* |
65
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
66
|
|
|
* @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher |
67
|
|
|
* @param array $languageFilter |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter) |
72
|
|
|
{ |
73
|
|
|
return array( |
74
|
|
|
'or' => $this->getCondition($criterion), |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Map field value to a proper Elasticsearch query representation. |
80
|
|
|
* |
81
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
82
|
|
|
* @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher |
83
|
|
|
* @param array $languageFilter |
84
|
|
|
* |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
public function visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter) |
88
|
|
|
{ |
89
|
|
|
return array( |
90
|
|
|
'bool' => array( |
91
|
|
|
'should' => $this->getCondition($criterion), |
92
|
|
|
'minimum_should_match' => 1, |
93
|
|
|
), |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.