Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Aliases fields to reduce fields count #107

Open
alexander-schranz opened this issue Feb 16, 2023 · 0 comments
Open

[Core] Aliases fields to reduce fields count #107

alexander-schranz opened this issue Feb 16, 2023 · 0 comments
Labels
features New feature or request SEAL Core Seal Core related issue

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Feb 16, 2023

If we have a document like this:

{
    "id": "1",
    "title": "New Blog",
    "article": "<article><h2>Some Subtitle<\/h2><p>A html field with some content<\/p><\/article>",
    "blocks": [
        {
            "type": "text",
            "title": "Title",
            "description": "<p>Description<\/p>"
        },
        {
            "type": "text",
            "title": "Title 2",
            "description": "<p>Description 2<\/p>"
        },
        {
            "type": "embed",
            "title": "Video"
        },
        {
            "type": "quote",
            "title": "Quote",
            "description": "<p>Some quote and more<\/p>"
        }
    ],
    "footer": {
        "title": "New Footer"
    }
}

Currently we are mapping each field into an own field itself.

[
    'id' => new Field\IdentifierField('id'),
    'title' => new Field\TextField('title'),
    'article' => new Field\TextField('article'),
    'blocks' => new Field\TypedField('blocks', 'type', [
        'text' => [
            'title' => new Field\TextField('title'),
            'description' => new Field\TextField('description'),
        ],
        'embed' => [
            'title' => new Field\TextField('title'),
        ],
        'text' => [
            'title' => new Field\TextField('title'),
            'description' => new Field\TextField('description'),
        ],
    ], multiple: true),
    'footer' => new Field\ObjectField('footer', [
        'title' => new Field\TextField('title'),
    ]),
];

This make that in complex Systems like CMS a lot fields are created, or a lot of converts are required to map all fields in a collected fields. I think it would be a great addition to make this possible out of the box via some alias field type. Lets say we map all content data into an own content field e.g.:

[
    'id' => new Field\IdentifierField('id'),
    'title' => new Field\TextField('title'),
    'block_titles' => new Field\TextField('content', multiple: true),
    'content' => new Field\TextField('content', multiple: true),
    'article' => new Field\AliasField('content'),
    'blocks' => new Field\TypedField('blocks', 'type', [
        'text' => [
            'title' => new Field\AliasField('block_titles'),
            'description' => new Field\AliasField('content'),
        ],
        'embed' => [
            'title' => new Field\AliasField('block_titles'),
        ],
        'text' => [
            'title' => new Field\AliasField('block_titles'),
            'description' => new Field\AliasField('content'),
        ],
    ], multiple: true),
    'footer' => new Field\ObjectField('footer', [
        'title' => new new Field\AliasField('content'),
    ]),
];

This way the Marshaller would be required to create a document like this:

{
    "id": "1",
    "title": "New Blog",
    "block_titles": [
        "Title",
        "Title 2",
        "Video",
        "Quote"
    ],
    "content": [
        "<article><h2>Some Subtitle<\/h2><p>A html field with some content<\/p><\/article>",
        "<p>Description<\/p>",
        "<p>Description 2<\/p>",
        "<p>Some quote and more<\/p>",
        "New Footer"
    ]
}

The question which is coming up here if we always should save the original JSON in a _raw field to so we get it back in the same way we are setting it. This would also mean that the documents inside search indexes get a little bit bigger as e.g. elasticsearch will save whole doc already in _source but with additonal _raw the _source will twice as big as without _raw. Example:

Current JSON Size: 494
Squashed JSON File: 265
Squashed with Raw JSON Size: 767

/c @chirimoya @wachterjohannes

This is also related to #200

@alexander-schranz alexander-schranz added features New feature or request SEAL Core Seal Core related issue labels Feb 16, 2023
@alexander-schranz alexander-schranz changed the title [Core] Aliases fields [Core] Aliases fields to reduce fields count Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
features New feature or request SEAL Core Seal Core related issue
Projects
None yet
Development

No branches or pull requests

1 participant