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

[10.x] Optional field definitions on model #812

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

MortenDHansen
Copy link
Contributor

Check if field definitions has been added on the model and use if that is the case

Reasoning
Search engine would like to have a definition of fields and their type. According to documentation, this is done in a (potentially huge) array in scout config. I propose an optional alternative where you can define the fields alongside your toSearchableArray() method for a searchable model.

  1. This has the benefit of colocation with the properties
    I feel this data belongs on the model rather in the global config, just like the toSearchableArray

  2. It opens the option to use php to generate some logic around the schema definition
    Consider you want to generate the index with a loop over the toSearchableArray keys detecting the typesense type automatically.

Notes
I propose to replace the field definitions if they are in the model. This ensures there is no breaks with the base approach and the definitions are only used if they are specifically added

I will of course update the documentation accordingly.

Check if field definitions has been added on the model and use if that is the case
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@MortenDHansen MortenDHansen marked this pull request as ready for review March 15, 2024 14:00
@driesvints driesvints changed the title Optional field definitions on model [10.x] Optional field definitions on model Mar 15, 2024
@jasonbosco
Copy link
Contributor

It opens the option to use php to generate some logic around the schema definition

This sounds interesting, but the reason we placed the "index settings" (aka schema definition) for Typesense in the Scout config is to maintain consistency with the other drivers, which place their own index settings in the Scout config as well.

So we wanted to maintain consistency.

If we make this change in the Typesense driver, we might want to also make similar changes in the other drivers as well...

But I'll defer to @driesvints or @taylorotwell if we want to have multiple ways to configure index settings - through the Scout config and also through model methods for all the drivers.

@MortenDHansen
Copy link
Contributor Author

MortenDHansen commented Mar 16, 2024

This sounds interesting, but the reason we placed the "index settings" (aka schema definition) for Typesense in the Scout config is to maintain consistency with the other drivers, which place their own index settings in the Scout config as well.

So we wanted to maintain consistency.

If we make this change in the Typesense driver, we might want to also make similar changes in the other drivers as well...

I would like to do an approach for all drivers if it's interesting, maybe except Algolia who made a separate scout extension completely.

@taylorotwell taylorotwell merged commit da58ba9 into laravel:10.x Mar 21, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants