Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

FieldIn.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field;
8
9 use eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher as Dispatcher;
10 use eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field;
11 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
12 use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator;
13 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
14
18 class FieldIn extends Field
19 {
27 public function canVisit(Criterion $criterion)
28 {
29 return
30 $criterion instanceof Criterion\Field &&
31 (
32 ($criterion->operator ?: Operator::IN) === Operator::IN ||
33 $criterion->operator === Operator::EQ ||
34 $criterion->operator === Operator::CONTAINS
35 );
36 }
37
47 protected function getCondition(Criterion $criterion)
48 {
49 $fieldNames = $this->getFieldNames($criterion, $criterion->target);
50
51 $values = (array)$criterion->value;
52
53 if (empty($fieldNames)) {
54 throw new InvalidArgumentException(
55 '$criterion->target',
56 "No searchable fields found for the given criterion target '{$criterion->target}'."
57 );
58 }
59
60 $fields = [];
61 foreach ($fieldNames as $name) {
62 $fields[] = 'fields_doc.' . $name;
63 }
64
65 $terms = [];
66 foreach ($values as $value) {
67 $terms[] = [
68 'multi_match' => [
69 'query' => $value,
70 'fields' => $fields,
71 ],
72 ];
73 }
74
75 return [
76 'bool' => [
77 'should' => $terms,
78 'minimum_should_match' => 1,
79 ],
80 ];
81 }
82
94 public function visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
95 {
96 $filter = [
97 'nested' => [
98 'path' => 'fields_doc',
99 'filter' => [
100 'query' => $this->getCondition($criterion),
101 ],
102 ],
103 ];
104
105 $fieldFilter = $this->getFieldFilter($languageFilter);
106
107 if ($languageFilter !== null) {
108 $filter['nested']['filter'] = [
109 'bool' => [
110 'must' => [
111 $fieldFilter,
112 $filter['nested']['filter'],
113 ],
114 ],
115 ];
116 }
117
118 return $filter;
119 }
120
132 public function visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
133 {
134 $fieldFilter = $this->getFieldFilter($languageFilter);
135
136 if ($fieldFilter === null) {
137 $query = [
138 'nested' => [
139 'path' => 'fields_doc',
140 'query' => $this->getCondition($criterion),
141 ],
142 ];
143 } else {
144 $query = [
145 'nested' => [
146 'path' => 'fields_doc',
147 'query' => [
148 'filtered' => [
149 'query' => $this->getCondition($criterion),
150 'filter' => $fieldFilter,
151 ],
152 ],
153 ],
154 ];
155 }
156
157 return $query;
158 }
159 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Field
The Field Criterion class.
Definition: API/Repository/Values/Content/Query/Criterion/Field.php:19
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\EQ
const EQ
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:16
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\IN
const IN
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:21
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\CONTAINS
const CONTAINS
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:30
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion.php:15
eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Invalid Argument Type Exception implementation.
Definition: Core/Base/Exceptions/InvalidArgumentException.php:20
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher
Dispatches Criterion objects to a visitor depending on the query context.
Definition: CriterionVisitorDispatcher.php:19
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\FieldFilterBase\getFieldFilter
getFieldFilter(array $languageFilter)
Returns filter condition for the given $languageFilter.
Definition: FieldFilterBase.php:27
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldIn
Visits the Field criterion with IN or EQ operator.
Definition: FieldIn.php:19
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldIn\visitQuery
visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
Map field value to a proper Elasticsearch query representation.
Definition: FieldIn.php:132
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldIn\getCondition
getCondition(Criterion $criterion)
Returns nested condition common for filter and query contexts.
Definition: FieldIn.php:47
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldIn\visitFilter
visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
Map field value to a proper Elasticsearch filter representation.
Definition: FieldIn.php:94
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldIn\canVisit
canVisit(Criterion $criterion)
Check if visitor is applicable to current criterion.
Definition: FieldIn.php:27
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\getFieldNames
getFieldNames(Criterion $criterion, $fieldDefinitionIdentifier, $fieldTypeIdentifier=null, $name=null)
Get field names.
Definition: Core/Search/Elasticsearch/Content/CriterionVisitor/Field.php:44
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator
Definition: Specifications.php:7
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion/Ancestor.php:7
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field
Definition: FieldIn.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.