Skip to content

Commit

Permalink
Create object and typed fields based on FlattenMarshaller
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jan 31, 2023
1 parent b21441c commit 2afad8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/seal-solr-adapter/SolrSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ public function createIndex(Index $index, array $options = []): ?TaskInterface
*
* @return array<string, mixed>
*/
private function createIndexFields(array $fields): array
private function createIndexFields(array $fields, string $prefix = ''): array
{
$indexFields = [];

foreach ($fields as $name => $field) {
$name = $prefix . $name;

match (true) {
$field instanceof Field\IdentifierField => null, // TODO define primary field
$field instanceof Field\TextField => $indexFields[$name] = [
Expand Down Expand Up @@ -159,18 +161,29 @@ private function createIndexFields(array $fields): array
'stored' => false,
'multiValued' => $field->multiple,
],
default => null,
/* TODO implement ObjectField and TypedField
$field instanceof Field\ObjectField => $fields[$name] = [
'type' => 'object',
'properties' => $this->createPropertiesMapping($field->fields),
],
$field instanceof Field\TypedField => $fields = \array_replace($properties, $this->createTypedFieldMapping($name, $field)),
$field instanceof Field\ObjectField => $indexFields = \array_replace($indexFields, $this->createIndexFields($field->fields, $name . '.')),
$field instanceof Field\TypedField => array_map(function($fields, $type) use ($name, &$indexFields) {
$indexFields = \array_replace($indexFields, $this->createIndexFields($fields, $name . '.'));
}, $field->types, array_keys($field->types)),
default => throw new \RuntimeException(sprintf('Field type "%s" is not supported.', get_class($field))),
*/
};
}

if ($prefix === null) {
$indexFields['_rawDocument'] = [
'name' => '_rawDocument',
'type' => 'string',
'indexed' => false,
'docValues' => false,
'stored' => false,
'multiValued' => false,
];
}

return $indexFields;
}

private function createIndexObjectFields(int|string $name, Field\ObjectField $field)
{
}
}
2 changes: 2 additions & 0 deletions packages/seal/Marshaller/FlattenMarshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @internal This class currently in discussion to be open for all adapters.
*
* The FlattenMarshaller will flatten all fields and save original document under a `_rawDocument` field.
* The FlattenMarshaller should only be used when the Search Engine does not support nested objects and so
* the Marshaller should used in many cases instead.
*/
final class FlattenMarshaller
{
Expand Down

0 comments on commit 2afad8a

Please sign in to comment.