I can’t say “no, not possible”, but I can’t say for certain how easy it would be to do either.
I’m looking most specifically at the load_indices
method that can be seen at https://github.com/WebDevStudios/wp-search-with-algolia/blob/2.8.1/includes/class-algolia-plugin.php#L277-L346
Here is where we set up the indices for “searchable posts types”, individual post types, terms, and users.
There is a algolia_indices
filter on line 322 that you could use to add your own, in similar ways that is shown in the previous lines there. Worth trying if you can re-use the Algolia_Posts_Index
class shown on line 303. However, I’m suspecting you’d probably need to extend your own class off of Algolia_Index
so that you could set your own unique ID like seen set at https://github.com/WebDevStudios/wp-search-with-algolia/blob/2.8.1/includes/indices/class-algolia-posts-index.php#L427-L429 Much of the rest could probably be copy/pasted for ease of implementation.
Last part would be the algolia_changes_watchers
filter on line 341 that you could use to set a new watcher class on, for the given index. For this, I think you very likely could just reuse the Algolia_Post_Changes_Watcher
class since it just needs an index specified and I am not seeing anything needing necessarily unique in it. Although if you look at that class, there may be some method you don’t need/want that could be trimmed down with your own changes watcher class too. I’ll leave that up to you.
You’d want to do a similar foreach loop like shown on line 324, so that you can set the enabled status, and whatnot. One thing to note with lines 325-326, you should be able to get that name prefix and client with similar code as below:
$algolia_plugin = \Algolia_Plugin_Factory::create();
$synced_indices_ids = $algolia_plugin->get_settings()->get_synced_indices_ids();
$index_name_prefix = $algolia_plugin->get_settings()->get_index_name_prefix();
$client = $algolia_plugin->get_api()->get_client();
A slightly more complete example can be seen at https://github.com/WebDevStudios/algolia-snippet-library/blob/main/indexing/reindex-on-comment-save.md where we have a snippet to re-index a post on comment save. Your case is simply adding a watcher though.