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] Provide Schema Loaders for supporting different Formats #115

Open
3 tasks
alexander-schranz opened this issue Feb 22, 2023 · 3 comments
Open
3 tasks
Labels
features New feature or request SEAL Core Seal Core related issue

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Feb 22, 2023

The Schema is currently created via PHP but maybe like in doctrine it make sense to create a Schema via other Formats like XML, YAML, JSON?

Current PHP Schema:

<?php

use Schranz\Search\SEAL\Schema\Field;
use Schranz\Search\SEAL\Schema\Index;
use Schranz\Search\SEAL\Schema\Schema;

return new Schema([
    'news' => new Index('news', [
        'id' => new Field\IdentifierField('id'),
        'title' => new Field\TextField('title'),
        'header' => new Field\TypedField('header', 'type', [
            'image' => [
                'media' => new Field\IntegerField('media'),
            ],
            'video' => [
                'media' => new Field\TextField('media', searchable: false),
            ],
        ]),
        'article' => new Field\TextField('article'),
        'blocks' => new Field\TypedField('blocks', 'type', [
            'text' => [
                'title' => new Field\TextField('title'),
                'description' => new Field\TextField('description'),
                'media' => new Field\IntegerField('media', multiple: true),
            ],
            'embed' => [
                'title' => new Field\TextField('title'),
                'media' => new Field\TextField('media', searchable: false),
            ],
        ], multiple: true),
        'footer' => new Field\ObjectField('footer', [
            'title' => new Field\TextField('title'),
        ]),
        'created' => new Field\DateTimeField('created'),
        'commentsCount' => new Field\IntegerField('commentsCount'),
        'rating' => new Field\FloatField('rating', sortable: true),
        'comments' => new Field\ObjectField('comments', [
            'email' => new Field\TextField('email', searchable: false),
            'text' => new Field\TextField('text'),
        ], multiple: true),
        'tags' => new Field\TextField('tags', multiple: true, filterable: true),
        'categoryIds' => new Field\IntegerField('categoryIds', multiple: true, filterable: true),
   ]),
]);

Which other formats should be supported:

  • YAML?
  • JSON?
  • XML?

Is the Core responsible for this formats or should the Core not care about additional Formats and Example the Symfony Bundle could us Symfony configuration tree instead, which out of the box supports Yaml, Xml, PHP Array, PHP Builder configuration.

But that would mean the definition would be framework specific, so own Schema Loaders which are not Framework specific maybe would make sense.

Maybe also other formats as the current PHP representation are not required?

In doctrine DBAL is also not responsible for this formats the ORM provide something so maybe the SEAL CORE should also not handle different formats or Schema Loaders, and maybe a future ODM would handle that, but that is another Ticket #81.

What also should be keep in mind does providing different formats improve a better developer experience or even hurt it as some answers to stackoverflow, github discussions, ... are written in just one format and not in another.

@alexander-schranz alexander-schranz added the SEAL Core Seal Core related issue label Feb 22, 2023
@alexander-schranz
Copy link
Member Author

alexander-schranz commented Feb 23, 2023

This is what a JSON Format would look like:

{
    "name": "news",
    "fields": {
         "id": {
              "type": "id"
         },
         "title": {
              "type": "text"
         },
         "header": {
              "type": "typed",
              "typeField": "type",
              "types": {
                   "image": {
                        "media": {
                            "type": "integer"
                        }
                   },
                   "video": {
                        "media": {
                            "type": "string",
                            "searchable": false
                        }
                   },
              }
         },
         "article": {
              "type": "text"
         },
         "blocks": {
              "type": "typed",
              "typeField": "type",
              "types": {
                   "text": {
                        "title": {
                            "type": "text"
                        },
                        "description": {
                            "type": "text"
                        },
                        "media": {
                            "type": "integer",
                            "multiple": true
                        }
                   },
                   "embed": {
                        "title": {
                            "type": "text"
                        }
                        "embed": {
                            "type": "text",
                            "searchable": false
                        }
                   }
              }
         },
         "footer": {
              "type": "object",
              "fields": {
                   "title": {
                        "type": "text"
                   }
              }
         },
         "created": {
              "type": "date"
         },
         "rating": {
              "type": "integer",
              "sortable": true
         },
         "commentsCount": {
              "type": "integer"
         },
         "comments": {
              "type": "object",
              "fields": {
                   "email": {
                        "type": "text",
                        "searchable": false
                   },
                   "text": {
                        "type": "text"
                   },
              }
         },
         "tags": {
              "type": "text",
              "multiple": true
         },
         "categoryIds": {
              "type": "integer",
              "multiple": true,
              "filterable": true
         }
    }
}

@alexander-schranz
Copy link
Member Author

alexander-schranz commented Feb 23, 2023

This is what a XML Format would look like:

<index name="news">
     <id name="id" />
     <text name="title" />
     <typed name="header" type-field="type">
         <type name="image">
              <integer name="media" />
         </type>
         <type name="video">
              <text name="media" />
         </type>
     </typed>
     <text name="article" />
     <typed name="blocks" type-field="type">
         <type name="image">
              <text name="title" />
              <text name="description" />
              <integer name="media" multiple="true" />
         </type>
         <type name="embed">
              <text name="title" />
              <text name="media" searchable="false" />
         </type>
     </typed>
     <object name="footer">
          <text name="title" />
     </object>
     <integer name="commentsCount" />
     <integer name="rating" sortable="true" />
     <object name="comments" multiple="true">
          <text name="email" searchable="false" />
          <text name="text" />
     </object>
     <text name="tags" multiple="true" filterable="true" />
     <integer name="categoryIds" multiple="true" filterable="true" />
</index>

@alexander-schranz
Copy link
Member Author

alexander-schranz commented Feb 23, 2023

The PHP classes could also in future be used as attributes for the ODM #81 implementation:

<?php

use Schranz\Search\SEAL\Schema\Field;
use Schranz\Search\SEAL\Schema\Index;

#[Index(name: 'page')]
class Page {
    #[Field\IdentifierField('id')]
    private string $id;
    
    #[Field\TextField('title')]
    private string $title;
    
    #[Field\TypedField('header', 'type', [
        'image' => [
            'media' => new Field\IntegerField('media'),
        ],
        'video' => [
            'media' => new Field\TextField('media', searchable: false),
        ],
    ])]
    private array $header;
    
    // ...
}

@alexander-schranz alexander-schranz changed the title Provide Schema Loaders for supporting different Formats [Core] Provide Schema Loaders for supporting different Formats May 10, 2023
@alexander-schranz alexander-schranz added the features New feature or request label May 10, 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