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

FieldRange.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 FieldRange extends Field
19 {
27 public function canVisit(Criterion $criterion)
28 {
29 return
30 $criterion instanceof Criterion\Field &&
31 (
32 $criterion->operator === Operator::LT ||
33 $criterion->operator === Operator::LTE ||
34 $criterion->operator === Operator::GT ||
35 $criterion->operator === Operator::GTE ||
36 $criterion->operator === Operator::BETWEEN
37 );
38 }
39
49 protected function getCondition(Criterion $criterion)
50 {
51 $fieldNames = $this->getFieldNames($criterion, $criterion->target);
52 $value = (array)$criterion->value;
53
54 if (empty($fieldNames)) {
55 throw new InvalidArgumentException(
56 '$criterion->target',
57 "No searchable fields found for the given criterion target '{$criterion->target}'."
58 );
59 }
60
61 $start = $value[0];
62 $end = isset($value[1]) ? $value[1] : null;
63 if (($criterion->operator === Operator::LT) || ($criterion->operator === Operator::LTE)) {
64 $end = $start;
65 $start = null;
66 }
67
68 $fields = [];
69 foreach ($fieldNames as $name) {
70 $fields[] = 'fields_doc.' . $name;
71 }
72
73 return [
74 'query_string' => [
75 'fields' => $fields,
76 'query' => $this->getQueryRange($criterion->operator, $start, $end),
77 ],
78 ];
79 }
80
92 public function visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
93 {
94 $filter = [
95 'nested' => [
96 'path' => 'fields_doc',
97 'filter' => [
98 'query' => $this->getCondition($criterion),
99 ],
100 ],
101 ];
102
103 $fieldFilter = $this->getFieldFilter($languageFilter);
104
105 if ($fieldFilter !== null) {
106 $filter['nested']['filter'] = [
107 'and' => [
108 $fieldFilter,
109 $filter['nested']['filter'],
110 ],
111 ];
112 }
113
114 return $filter;
115 }
116
128 public function visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
129 {
130 $query = [
131 'bool' => [
132 'should' => $this->getCondition($criterion),
133 'minimum_should_match' => 1,
134 ],
135 ];
136
137 $fieldFilter = $this->getFieldFilter($languageFilter);
138
139 if ($fieldFilter === null) {
140 $query = [
141 'nested' => [
142 'path' => 'fields_doc',
143 'query' => $this->getCondition($criterion),
144 ],
145 ];
146 } else {
147 $query = [
148 'nested' => [
149 'path' => 'fields_doc',
150 'query' => [
151 'filtered' => [
152 'query' => $this->getCondition($criterion),
153 'filter' => $fieldFilter,
154 ],
155 ],
156 ],
157 ];
158 }
159
160 return $query;
161 }
162 }
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\LT
const LT
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:19
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\LTE
const LTE
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:20
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\GT
const GT
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:17
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\BETWEEN
const BETWEEN
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:22
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\GTE
const GTE
Definition: API/Repository/Values/Content/Query/Criterion/Operator.php:18
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\FieldRange
Visits the Field criterion with range operators (LT, LTE, GT, GTE and BETWEEN).
Definition: FieldRange.php:19
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldRange\getCondition
getCondition(Criterion $criterion)
Returns nested condition common for filter and query contexts.
Definition: FieldRange.php:49
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldRange\visitFilter
visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
Map field value to a proper Elasticsearch filter representation.
Definition: FieldRange.php:92
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldRange\visitQuery
visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter)
Map field value to a proper Elasticsearch query representation.
Definition: FieldRange.php:128
eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitor\Field\FieldRange\canVisit
canVisit(Criterion $criterion)
Check if visitor is applicable to current criterion.
Definition: FieldRange.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\Core\Search\Elasticsearch\Content\CriterionVisitor\getQueryRange
getQueryRange($operator, $start, $end)
Get Elasticsearch range query.
Definition: CriterionVisitor.php:80
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+.