Help setting up Algolia search plugin

With the code you suggested me (increasing memory limit), I manage to get over the fatal error I had before.

Now though, if I use the following filter for a template in config.php

'filter' => function($page) { return $page->isVisible() && $page->indexable()->bool(); },
the widget in the panel returns
Number of indexable pages: 0

If instead I remove the indexable() check:
'filter' => function($page) { return $page->isVisible(); },
the widget correctly returns:
Number of indexable pages: 8606

What’s $page->indexable() checking? I suppose somehow my pages don’t pass whatever check its doing.

When I then hit Manual Refresh, the panel loads for few minute, until finally returns the error:
Notice: Undefined index: tinyurl.enabled in /Users/Desktop/site/kirby/core/page.php on line 197

In my Algolia dashboard, my index now is made of 8606 pages, so seems that the index has been uploaded.

It’s just an example. In this case, it would check if a checkbox field named “indexable” is checked. But if you don’t have that field, it of course doesn’t work. You don’t need to have it though, the filter functions can check for whatever condition you want. :slight_smile:

This was a bug in Kirby 2.3. Have you upgraded to Kirby 2.3.1? The error should then disappear.

Thanks for the explanation about indexable()! :slight_smile:
Updating Kirby did indeed fix the bug.

I still can’t manage to get Algolia index these 8000 pages, especially if I index few fields that contain lots of text.
After a minute or so of the panel loading after I hit “manual refresh” it returns the error:

Hosts unreachable: Operation timed out after 30000 milliseconds with 0 bytes received,Operation timed out after 30000 milliseconds with 0 bytes received,Operation timed out after 40010 milliseconds with 0 bytes received,Operation timed out after 40000 milliseconds with 0 bytes received

Is there anywhere the plugin stores the JSON indexed file, so that I can try upload it manually into algolia?

The plugin does not store the data, but you could modify the plugin to store it as JSON.

I have noticed that my algolia index contained the absolute URL rather then relative:

objectID: pages/page-title-x
url: "http://localhost/site/pages/page-title-x"

So I tweaked my config.php this way:

c::set('algolia.fields', array('url', 'intendedTemplate', 'title', 'text'));
c::set('algolia.templates', array(
    'page-x' => array(
        'filter' => function ($page) {
            return $page->isVisible() && $page->indexable()->bool();
        },
        'fields' => array(
            'uri',
            'image' => function ($page) {
                $image = $page->images()->first();
                return ($image) ? $image->uri() : null;
            }
        )
    ),

And the result in the algolia index is:

objectID: pages/page-title-x
uri: "pages/page-title-x"

Is there a way for me to export the uri as url in algolia? I would like to obtain:

objectID: pages/page-title-x
url: "pages/page-title-x"

I tried the following, but it didn’t work:

 c::set('algolia.templates', array(
    'page-x' => array(
        'filter' => function ($page) {
            return $page->isVisible() && $page->indexable()->bool();
        },
        'fields' => array(
            'uri' => 'url',
        )
    ),

Try this:

 c::set('algolia.templates', array(
    'page-x' => array(
        'filter' => function ($page) {
            return $page->isVisible() && $page->indexable()->bool();
        },
        'fields' => array(
            'url' => function($page) {
                return $page->uri();
            },
        )
    ),

But why do you need to store the URI separately? It is already stored as objectID anyway. :slight_smile:

Great! Thank you!! You’re right about objectID! I should probably just use that :slight_smile:

There is now a new release of the Algolia plugin that uploads the pages in smaller batches when indexing. This should reduce the RAM usage and make the error you were having go away. Could you please try if the new version fixes it for you?