2017 © Pedro Peláez
 

cakephp-plugin cakephp-algolia

Algolia plugin for CakePHP

image

be-mohand/cakephp-algolia

Algolia plugin for CakePHP

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Algolia plugin for CakePHP

Installation

You can install this plugin into your CakePHP application using composer., (*1)

The recommended way to install composer packages is:, (*2)

composer require be-mohand/cakephp-algolia

Configuration

In your configuration file (for instance app_local.php), add the Algolia key configuration:, (*3)

<?php

return [
    'Algolia' => [
        'appId' => 'xxxx',
        'apiKey' => [
            'backend' => 'xxxxxxxxxxxx',
            'search' => 'xxxxxxxxxxxx',
        ],
        'index' => 'your_index_name',
    ]
];

You can create your Algolia account at at https://www.algolia.com., (*4)

Load the Algolia.Algolia behavior in the Table you want to index and add a virtual field in the corresponding entity:, (*5)

    protected $_virtual = ['objectID'];

    public function _getObjectID()
    {
        return $this->id;
    }

Import your data in Algolia

Before starting to use the Algolia powerful search engine, you have to sync your data with Algolia database., (*6)

For the purpose, you can use the ImportToAlgoliaShell like this:, (*7)

bin/cake Algolia.ImportToAlgolia --url your_public_url

your_public_url should point to a json file. You can create this json file on the fly with an action like this:, (*8)


Warning: an objectID key is required. Use the primary key, (*9)

Implementing search in front

Algolia provides an out of box solution for building a search engine. It is named instantsearch.js., (*10)

Start to load the needed js and css files in your template:, (*11)

<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.css" />
<script src="//cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>

You need a dummy action with a template where Algolia files are loaded. You can use an example of a working template in Algolia/src/Template/example.ctp., (*12)

Auto-Update entities when modified/deleted

Known issues

When the DebugKit is loaded, we have this error: toolbar.js:62 Refused to get unsafe header "X-DEBUGKIT-ID", (*13)

Thanks

The starting point of the plugin is the excellent article from startutorial., (*14)

Thanks to the author., (*15)

TODO

  • Manage conditions of the entities we want to index
  • Manage the query to reindex when creating/updating from the AlgoliaBehavior
  • indicate a custom ranking
  • manage the searchableAttributes
  • manage synonyms

The Versions

10/07 2017

dev-master

9999999-dev

Algolia plugin for CakePHP

  Sources   Download

The Requires

 

The Development Requires