• Resolved arjendejong

    (@arjendejong)


    Hi,

    I’ve got a multisite (4 websites) set up with Algolia in each subsite with an unique prefix. Is it possible to load all indexes from all subsites so that a user can search in a specific subsite and see the results from all subsites, essentially creating a global search? Ideally I’d like to have the name of the subsite after each post type label above the results. In the current situation I’m not seeing any results from other subsites.

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @arjendejong

    Yes and no all at once. I know that with our Pro/paid addon, specifically with version 1.3.x we added what we call network-wide indexing. This setting essentially enables pushing content from each subsite into a single index, and performs searches against that one index. It does end up requiring usage of Instantsearch, and not the native search integration because of limits in querying across subsites.

    That said, it wouldn’t be workable for cases of multiple indexes like it sounds like you have set up, with each site having their own.

    Thread Starter arjendejong

    (@arjendejong)

    Thank you for answer, @tw2113!

    I’ve been experimenting in the mean time, and I’ve got something working for the autocomplete:

    add_filter('algolia_autocomplete_config', function ($config) {
    
    if (is_admin()) {
    
    return $config;
    
    }
    
    $original_plugin = Algolia_Plugin::get_instance();
    
    $original_prefix = $original_plugin->get_settings()->get_index_name_prefix();
    
    $sites = get_sites(['deleted' => false]);
    
    $configs = [];
    
    foreach ($sites as $site) {
    
    switch_to_blog($site->blog_id);
    
    $plugin = Algolia_Plugin::get_instance();
    
    $settings = $plugin->get_settings();
    
    if ($settings->get_autocomplete_enabled() === 'no') {
    
    restore_current_blog();
    
    continue;
    
    }
    
    $prefix = $settings->get_index_name_prefix();
    
    $config = $settings->get_autocomplete_config();
    
    foreach ($config as $key => &$entry) {
    
    if (!isset($entry['index_id'])) {
    
    unset($config[$key]);
    
    restore_current_blog();
    
    continue;
    
    }
    
    $index = $plugin->get_index($entry['index_id']);
    
    if (null === $index) {
    
    unset($config[$key]);
    
    restore_current_blog();
    
    continue;
    
    }
    
    $entry['index_name'] = str_replace($original_prefix, $prefix, $index->get_name());
    
    $entry['enabled'] = true;
    
    }
    
    $configs = array_merge($configs, $config);
    
    restore_current_blog();
    
    }
    
    return $configs;
    
    });

    This piece of code allows me to show results for the subsites that have Algolia indexes enabled. What do you think about this?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If it works, it works. Could definitely see some bigger hurdles trying to do that with Instantsearch though, as that’s a different lil beast.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Global multisite search with multiple indexes’ is closed to new replies.