Kirby 3 + Algolia

I have several projects that rely on the Kirby 2 Algolia plugin. My understanding is that there’s no Kirby 3-compatible plugin for Algolia. Does anyone know if an updated plugin is in the works, or a recommendation for an alternative way to accomplish integration?

There’s not standalone plugin, but you can basically use the files used on the getirby.com website.

Repo: https://github.com/getkirby/getkirby.com
Relevant files: Searching with grouped words and operators

2 Likes

FYI

The search on/in getkirby.com site is based on Awesomplete and vanilla search.

The plugin in the Git-Repo for Algola does not update content like it should.

Is there a solid Algolia solution in the pipes for Kirby?

Yes, the Algolia plugin in the getkirby.com GitHub repo is very rudimentary. I adapted it and made it more closely mirror the Kirby 2 Algolia plugin by adding a route (for manual reindexing) and hooks to automatically update the index when content changes. It’s been a while since I set up the plugin but I’ve used it on multiple Kirby 3 sites since without issue. Essentially, this is what I added to index.php in the plugin.

Kirby::plugin('kirby/algolia', [
  'routes' => [
    [
        'pattern' => 'algolia/index',
        'action'  => function () {
          algolia()->index();
          echo 'Index updated';
        }
    ],
  ],
  'hooks' => [
    'page.create:after' => function ($page) {
      return algolia()->insertPage($page);
    },
    'page.update:after' => function ($newPage) {
      return algolia()->updatePage($newPage);
    },
    'page.delete:before' => function ($page) {
      return algolia()->deletePageRecursive($page);
    },
    'page.changeNum' => function ($page) {
      return algolia()->updatePage($page);
    },
    'page.changeStatus:before' => function ($page) {
      return algolia()->updatePage($page);
    },
    'page.changeSlug:after' => function ($newPage, $oldPage) {
       return algolia()->movePage($oldPage, $newPage);
    }
  ],
]);
4 Likes

Thank you for sharing @nigel. I appreciate it.

Was looking at the v2 plugin myself. Looking forward to try this out.

Added: Works like a charm.