-
-
Notifications
You must be signed in to change notification settings - Fork 599
[5.x] Provide search index name callback #10435
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
Conversation
|
Ah yes, sure. I am not that config-file fan any more but as Statamic has a lot of config files it would fit too. Also keep in mind that there are other search providers as well. Narrowing down this to Algolia could lead to other PR's :) |
Good point! |
|
I went the config file road in the other PR because that's the way it is done in Laravel Scout. In the end it's more about having the opportunity to have the value in your env file. It doesn't have to be in the |
|
I'm sure some folks are tied up with Laracon/traveling, but happy to help support this in any way! We're about to work on a project that needs this type of capability. Any documentation necessary here? I can write that up if so if it'll help get this merged sooner! |
You can always composer patch it in. |
|
Good idea, @edalzell! In the meantime, if the core team could use an extra pair of hands I'm happy to jump in! |
|
Hi @jasonvarga. I added a test for the search index name callback. This somehow took longer as expected as the Please let me know if this works for you and if there is anything missing. Thanks! |
- name is immediately resolved and receives the original name and locale - test for getting names without custom resolvers - test for getting names with locales - the test wants the index's name so we can call it statically before newing up an instance
|
Sorry for the delay. Thanks for your patience. I've adjusted this so that your resolver function accepts the original name, and the locale. You'll need to put the locale on that string if you're dealing with multisite. AlgoliaIndex::resolveNameUsing(function ($name, $locale) {
return 'prefix_'.$name.'_'.$locale;
// prefix_name_locale
});I also updated the tests. |
Currently Statamic always generates search index names like this
$locale ? $name.'_'.$locale : $name.When using different environments (staging, production) and a cloud search provider (e.g. Algolia) index names tpyically collide. Staging updates overwrite those from production and vice versa.
At least in the lower pricing plans Algolia has a limit of 1 app per account and per app isolation is also often a configuration overhead. So an environment prefix for the search index name would be handy?
Afaik there a two approaches to get this solved in user land:
search.phpWith this PR it would possible to override the generating of index names by setting a callback within a ServiceProvider's boot method e.g. like this:
No breaking chances, default name generation is preserved.
Any chance that this is getting merged? :)
Thanks!
Closes statamic/ideas#1202