Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Fix #1: Panel indexing widget
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Jul 15, 2016
1 parent 94b7609 commit 291085e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ function algolia() {
return Kirby\Algolia::instance();
}

// Register the Panel widget
if(c::get('algolia.widget', true) && function_exists('panel')) {
$kirby->set('widget', 'algolia', __DIR__ . DS . 'widgets' . DS . 'algolia');

// Register the route for the widget
panel()->routes([
[
'pattern' => 'widgets/algolia/index',
'method' => 'GET',
'filter' => 'auth',
'action' => function() {
algolia()->index();

panel()->notify(':)');
panel()->redirect('/');
}
]
]);
}

/**
* Panel hooks
*
Expand Down
9 changes: 9 additions & 0 deletions lib/algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ public static function formatPage(Page $page) {
return $data;
}

/**
* Returns the number of indexable pages
*
* @return int
*/
public function objectCount() {
return site()->index()->filter(array($this, 'isIndexable'))->count();
}

/**
* Returns an array of data to send to Algolia
* Includes all whitelisted pages and formats their data according to the configuration
Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ If you only want to use manual indexing, you can disable the automatic indexing
c::set('algolia.autoindex', false);
```

#### Indexing widget

The Algolia plugin includes a Panel widget that allows Panel users to manually index the site. You can disable this widget with the following option:

```php
c::set('algolia.widget', false);
```

### Search options

Algolia has [many search options](https://www.algolia.com/doc/php#full-text-search-parameters) to fine-tune the search results. You can set these in your configuration like this:
Expand All @@ -130,6 +138,8 @@ algolia()->index();
This will create a new temporary index, upload all indexable pages and replace the main index with the temporary index.
Please note that manual indexing will use roughly as many Algolia "Operations" as you have indexable pages each time you call the `index` method. The amount of included/free "Operations" per month depends on your Algolia plan.

There is also a Panel widget for this that is enabled by default.

## Search

The plugin also provides a method to query/search the index from the backend. It is generally recommended to use [Algolia's JavaScript library](https://www.algolia.com/doc/javascript#quick-start) to avoid the round-trip to your server, but you should also have a server-side fallback results page, which you can implement using the `search` method:
Expand Down
3 changes: 3 additions & 0 deletions widgets/algolia/algolia.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="dashboard-box">
<div class="text">Number of indexable pages: <strong><?= $count ?></strong></div>
</div>
32 changes: 32 additions & 0 deletions widgets/algolia/algolia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Kirby;

// Kirby dependencies
use Tpl;

/**
* Algolia indexing widget
*
* @author Lukas Bestle <[email protected]>
* @license MIT
* @link https://getkirby.com
*/

return array(
'title' => [
'text' => 'Search Index',
'compressed' => false
],
'options' => [
[
'text' => 'Manual Refresh',
'icon' => 'refresh',
'link' => purl('widgets/algolia/index')
]
],
'html' => function() {
$count = algolia()->objectCount();
return tpl::load(__DIR__ . DS . 'algolia.html.php', compact('count'));
}
);

0 comments on commit 291085e

Please sign in to comment.