Download the PHP package kvz/elasticsearch without Composer
On this page you can find all versions of the php package kvz/elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kvz/elasticsearch
More information about kvz/elasticsearch
Files in kvz/elasticsearch
Informations about the package elasticsearch
About
Elastic search was recently used to index the Firefox4 twitter stream and make it searchable. It's based on Lucene and has a simple JSON based interface that you can use to store objects and search through them (for instance even with CURL).
This also makes it easy to have your search indexes be updated in realtime whenever your CakePHP models change data. Cause basically all we'd have to do is do a Curl PUT, DELETE, etc to also make the change in Elastisearch with every afterSave and afterDelete.
This plugin provides
- a behavior to automatically update your indexes
- a shell task to do full index fills
- a generic search component that you can attach to your AppController and will intercept search actions on enabled models. Will return results in JSON format for easy AJAX integration.
Installation
You'll need the PHP curl libraries installed.
Server
CakePHP Plugin
As a fake submodule
As a real submodule
Using composer
Integration
Database
Config/database.php
Model
Models/Ticket.php
(minimal example)
Models/Ticket.php
(with raw sql for huge datasets)
Models/Ticket.php
(full example)
Controller
To automatically enable a /<controller>/searcher
url on all models
that have elastic search enabled, use:
Controller/AppController.php
This component will only actually fire when the Controller->modelClass has the searchable behavior attached.
I chose for this method (vs a dedicated SearchesController) so ACLing is easier. e.g. You may already have an ACL for /tickets/*, so /tickets/search will automatically be restricted the same way.
Generic search
If you want to search on all models, you could make a dedicated search controller and instruct to search on everything like so:
One known limitation is that the Elasticsearch plugin will only look at the
first configured Model for configuration parameters like searcher_param
and searcher_action
.
Try it
From your shell:
From your browser
jQuery integration
Let's look at an integration example that uses jQuery UI's autocomplete.
Assuming you have included that library, and have an input field with attributes
id="main-search"
and target="/tickets/searcher/q:*{query}*"
:
Note
- There also is an unmaintained legacy cakephp 1.3 branch