Skip to content

Commit ab1fe52

Browse files
Keep facet flag in mind in SchemaManager of different Adapters
1 parent 927e379 commit ab1fe52

File tree

8 files changed

+63
-48
lines changed

8 files changed

+63
-48
lines changed

packages/seal-algolia-adapter/src/AlgoliaSchemaManager.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ public function createIndex(Index $index, array $options = []): TaskInterface|nu
9292
}
9393
}
9494

95+
$filterableAndFacetFields = \array_unique([
96+
...$index->filterableFields,
97+
...$index->facetFields,
98+
]);
99+
95100
$attributes = [
96101
'searchableAttributes' => $index->searchableFields,
97-
'attributesForFaceting' => $index->filterableFields,
102+
'attributesForFaceting' => $filterableAndFacetFields,
98103
'replicas' => $replicas,
99104
];
100105

packages/seal-elasticsearch-adapter/src/ElasticsearchSchemaManager.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -86,40 +86,40 @@ private function createPropertiesMapping(array $fields): array
8686
$field instanceof Field\IdentifierField => $properties[$name] = [
8787
'type' => 'keyword',
8888
'index' => $field->searchable,
89-
'doc_values' => $field->filterable || $field->sortable, // @phpstan-ignore-line
89+
'doc_values' => $field->filterable || $field->sortable || $field->facet, // @phpstan-ignore-line
9090
],
9191
$field instanceof Field\TextField => $properties[$name] = \array_replace([
9292
'type' => 'text',
9393
'index' => $field->searchable,
94-
], ($field->filterable || $field->sortable) ? [
94+
], ($field->filterable || $field->sortable || $field->facet) ? [
9595
'fields' => [
9696
'raw' => ['type' => 'keyword'],
9797
],
9898
] : []),
9999
$field instanceof Field\BooleanField => $properties[$name] = [
100100
'type' => 'boolean',
101101
'index' => $field->searchable,
102-
'doc_values' => $field->filterable || $field->sortable,
102+
'doc_values' => $field->filterable || $field->sortable || $field->facet,
103103
],
104104
$field instanceof Field\DateTimeField => $properties[$name] = [
105105
'type' => 'date',
106106
'index' => $field->searchable,
107-
'doc_values' => $field->filterable || $field->sortable,
107+
'doc_values' => $field->filterable || $field->sortable || $field->facet,
108108
],
109109
$field instanceof Field\IntegerField => $properties[$name] = [
110110
'type' => 'integer',
111111
'index' => $field->searchable,
112-
'doc_values' => $field->filterable || $field->sortable,
112+
'doc_values' => $field->filterable || $field->sortable || $field->facet,
113113
],
114114
$field instanceof Field\FloatField => $properties[$name] = [
115115
'type' => 'float',
116116
'index' => $field->searchable,
117-
'doc_values' => $field->filterable || $field->sortable,
117+
'doc_values' => $field->filterable || $field->sortable || $field->facet,
118118
],
119119
$field instanceof Field\GeoPointField => $properties[$name] = [
120120
'type' => 'geo_point',
121121
'index' => $field->searchable,
122-
'doc_values' => $field->filterable || $field->sortable,
122+
'doc_values' => $field->filterable || $field->sortable || $field->facet, // @phpstan-ignore-line
123123
],
124124
$field instanceof Field\ObjectField => $properties[$name] = [
125125
'type' => 'object',

packages/seal-loupe-adapter/src/LoupeHelper.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,15 @@ private function createAndDumpConfiguration(Index $index): Configuration
139139

140140
private function createConfiguration(Index $index): Configuration
141141
{
142+
$filterableAndFacetFields = \array_unique([
143+
...$index->filterableFields,
144+
...$index->facetFields,
145+
]);
146+
142147
return Configuration::create()
143148
->withPrimaryKey($index->getIdentifierField()->name)
144149
->withSearchableAttributes(\array_map(fn (string $field) => $this->formatField($field), $index->searchableFields))
145-
->withFilterableAttributes(\array_map(fn (string $field) => $this->formatField($field), $index->filterableFields))
150+
->withFilterableAttributes(\array_map(fn (string $field) => $this->formatField($field), $filterableAndFacetFields))
146151
->withSortableAttributes(\array_map(fn (string $field) => $this->formatField($field), $index->sortableFields));
147152
}
148153

packages/seal-meilisearch-adapter/src/MeilisearchSchemaManager.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ public function createIndex(Index $index, array $options = []): TaskInterface|nu
6565
],
6666
);
6767

68+
$filterableAndFacetFields = \array_unique([
69+
...$index->filterableFields,
70+
...$index->facetFields,
71+
]);
72+
6873
$attributes = [
6974
'searchableAttributes' => $index->searchableFields,
70-
'filterableAttributes' => $index->filterableFields,
75+
'filterableAttributes' => $filterableAndFacetFields,
7176
'sortableAttributes' => $index->sortableFields,
7277
];
7378

packages/seal-opensearch-adapter/src/OpensearchSchemaManager.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -81,45 +81,45 @@ private function createPropertiesMapping(array $fields): array
8181
match (true) {
8282
$field instanceof Field\IdentifierField => $properties[$name] = [
8383
'type' => 'keyword',
84-
'index' => $field->searchable || $field->filterable, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
85-
'doc_values' => $field->filterable,
84+
'index' => $field->searchable || $field->filterable || $field->facet, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
85+
'doc_values' => $field->filterable || $field->facet, // @phpstan-ignore-line
8686
],
8787
$field instanceof Field\TextField => $properties[$name] = \array_replace([
8888
'type' => 'text',
89-
'index' => $field->searchable || $field->filterable, // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
90-
], ($field->filterable || $field->sortable) ? [
89+
'index' => $field->searchable || $field->filterable || $field->facet, // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
90+
], ($field->filterable || $field->sortable || $field->facet) ? [
9191
'fields' => [
9292
'raw' => [
9393
'type' => 'keyword',
94-
'index' => $field->searchable || $field->filterable, // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
95-
'doc_values' => $field->filterable,
94+
'index' => $field->searchable || $field->filterable || $field->facet, // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
95+
'doc_values' => $field->filterable || $field->facet,
9696
],
9797
],
9898
] : []),
9999
$field instanceof Field\BooleanField => $properties[$name] = [
100100
'type' => 'boolean',
101-
'index' => $field->searchable || $field->filterable, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
102-
'doc_values' => $field->filterable,
101+
'index' => $field->searchable || $field->filterable || $field->facet, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
102+
'doc_values' => $field->filterable || $field->facet,
103103
],
104104
$field instanceof Field\DateTimeField => $properties[$name] = [
105105
'type' => 'date',
106-
'index' => $field->searchable || $field->filterable, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
107-
'doc_values' => $field->filterable,
106+
'index' => $field->searchable || $field->filterable || $field->facet, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
107+
'doc_values' => $field->filterable || $field->facet,
108108
],
109109
$field instanceof Field\IntegerField => $properties[$name] = [
110110
'type' => 'integer',
111-
'index' => $field->searchable || $field->filterable, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
112-
'doc_values' => $field->filterable,
111+
'index' => $field->searchable || $field->filterable || $field->facet, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
112+
'doc_values' => $field->filterable || $field->facet,
113113
],
114114
$field instanceof Field\FloatField => $properties[$name] = [
115115
'type' => 'float',
116-
'index' => $field->searchable || $field->filterable, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
117-
'doc_values' => $field->filterable,
116+
'index' => $field->searchable || $field->filterable || $field->facet, // @phpstan-ignore-line // TODO recheck doc_values https://github.com/php-cmsig/search/issues/65
117+
'doc_values' => $field->filterable || $field->facet,
118118
],
119119
$field instanceof Field\GeoPointField => $properties[$name] = [
120120
'type' => 'geo_point',
121121
'index' => $field->searchable,
122-
'doc_values' => $field->filterable || $field->sortable,
122+
'doc_values' => $field->filterable || $field->sortable || $field->facet, // @phpstan-ignore-line
123123
],
124124
$field instanceof Field\ObjectField => $properties[$name] = [
125125
'type' => 'object',

packages/seal-redisearch-adapter/src/RediSearchSchemaManager.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ private function createJsonFields(array $fields, string $prefix = '', string $js
122122
}
123123
$name = $prefix . $name;
124124

125-
// ignore all fields without search, sort or filterable activated
126-
if (!$field->searchable && !$field->sortable && !$field->filterable) {
125+
// ignore all fields without search, sort, filterable or facet activated
126+
if (!$field->searchable && !$field->sortable && !$field->filterable && !$field->facet) {
127127
continue;
128128
}
129129

@@ -133,7 +133,7 @@ private function createJsonFields(array $fields, string $prefix = '', string $js
133133
'type' => 'TAG',
134134
'searchable' => $field->searchable,
135135
'sortable' => $field->sortable,
136-
'filterable' => $field->filterable,
136+
'filterable' => $field->filterable || $field->facet, // @phpstan-ignore-line
137137
],
138138
$field instanceof Field\TextField, $field instanceof Field\DateTimeField => $indexFields = \array_replace($indexFields, $field->searchable ? [
139139
$name => [
@@ -143,35 +143,35 @@ private function createJsonFields(array $fields, string $prefix = '', string $js
143143
'sortable' => false,
144144
'filterable' => false,
145145
],
146-
] : [], $field->filterable || $field->sortable ? [
146+
] : [], $field->filterable || $field->facet || $field->sortable ? [
147147
$name . '.raw' => [
148148
'jsonPath' => $jsonPathRaw,
149149
'type' => 'TAG',
150150
'searchable' => false,
151151
'sortable' => $field->sortable,
152-
'filterable' => $field->filterable,
152+
'filterable' => $field->filterable || $field->facet,
153153
],
154154
] : []),
155155
$field instanceof Field\BooleanField => $indexFields[$name] = [
156156
'jsonPath' => $jsonPath,
157157
'type' => 'TAG',
158158
'searchable' => $field->searchable,
159159
'sortable' => $field->sortable,
160-
'filterable' => $field->filterable,
160+
'filterable' => $field->filterable || $field->facet,
161161
],
162162
$field instanceof Field\IntegerField, $field instanceof Field\FloatField => $indexFields[$name] = [
163163
'jsonPath' => $jsonPath,
164164
'type' => 'NUMERIC',
165165
'searchable' => $field->searchable,
166166
'sortable' => $field->sortable,
167-
'filterable' => $field->filterable,
167+
'filterable' => $field->filterable || $field->facet,
168168
],
169169
$field instanceof Field\GeoPointField => $indexFields[$name] = [
170170
'jsonPath' => $jsonPath,
171171
'type' => 'GEO',
172172
'searchable' => $field->searchable,
173173
'sortable' => $field->sortable,
174-
'filterable' => $field->filterable,
174+
'filterable' => $field->filterable || $field->facet, // @phpstan-ignore-line
175175
],
176176
$field instanceof Field\ObjectField => $indexFields = \array_replace($indexFields, $this->createJsonFields($field->fields, $name, $jsonPath)),
177177
$field instanceof Field\TypedField => \array_map(function ($fields, $type) use ($name, &$indexFields, $jsonPath, $field) {

packages/seal-solr-adapter/src/SolrSchemaManager.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
147147
'name' => $name,
148148
'type' => $field->searchable ? 'text_general' : 'string',
149149
'indexed' => $field->searchable,
150-
'docValues' => $field->filterable || $field->sortable,
150+
'docValues' => $field->filterable || $field->sortable || $field->facet,
151151
'stored' => true, // required to be set to stored for highlighting
152152
'useDocValuesAsStored' => false,
153153
'multiValued' => $isMultiple,
@@ -156,7 +156,7 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
156156
'name' => $name,
157157
'type' => 'boolean',
158158
'indexed' => $field->searchable,
159-
'docValues' => $field->filterable || $field->sortable,
159+
'docValues' => $field->filterable || $field->sortable || $field->facet,
160160
'stored' => false,
161161
'useDocValuesAsStored' => false,
162162
'multiValued' => $isMultiple,
@@ -165,7 +165,7 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
165165
'name' => $name,
166166
'type' => 'pdate',
167167
'indexed' => $field->searchable,
168-
'docValues' => $field->filterable || $field->sortable,
168+
'docValues' => $field->filterable || $field->sortable || $field->facet,
169169
'stored' => false,
170170
'useDocValuesAsStored' => false,
171171
'multiValued' => $isMultiple,
@@ -174,7 +174,7 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
174174
'name' => $name,
175175
'type' => 'pint',
176176
'indexed' => $field->searchable,
177-
'docValues' => $field->filterable || $field->sortable,
177+
'docValues' => $field->filterable || $field->sortable || $field->facet,
178178
'stored' => false,
179179
'useDocValuesAsStored' => false,
180180
'multiValued' => $isMultiple,
@@ -183,7 +183,7 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
183183
'name' => $name,
184184
'type' => 'pfloat',
185185
'indexed' => $field->searchable,
186-
'docValues' => $field->filterable || $field->sortable,
186+
'docValues' => $field->filterable || $field->sortable || $field->facet,
187187
'stored' => false,
188188
'useDocValuesAsStored' => false,
189189
'multiValued' => $isMultiple,
@@ -192,7 +192,7 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
192192
'name' => $name,
193193
'type' => 'location',
194194
'indexed' => $field->searchable,
195-
'docValues' => $field->filterable || $field->sortable,
195+
'docValues' => $field->filterable || $field->sortable || $field->facet, // @phpstan-ignore-line
196196
'stored' => false,
197197
'useDocValuesAsStored' => false,
198198
'multiValued' => $isMultiple,
@@ -204,8 +204,8 @@ private function createIndexFields(array $fields, string $prefix = '', bool $isP
204204
default => throw new \RuntimeException(\sprintf('Field type "%s" is not supported.', $field::class)),
205205
};
206206

207-
if ($field instanceof Field\TextField && $field->searchable && ($field->filterable || $field->sortable)) {
208-
// add additional raw field for field which is filterable/sortable but also searchable
207+
if ($field instanceof Field\TextField && $field->searchable && ($field->filterable || $field->sortable || $field->facet)) {
208+
// add additional raw field for field which is filterable/sortable/facet but also searchable
209209
$fieldSettings = $indexFields[$name];
210210

211211
$fieldSettings['name'] = $name . '.raw';

0 commit comments

Comments
 (0)