Download the PHP package taq/torm-elastic without Composer
On this page you can find all versions of the php package taq/torm-elastic. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download taq/torm-elastic
More information about taq/torm-elastic
Files in taq/torm-elastic
Package torm-elastic
Short Description ElasticSearch integration for TORM
License GPL
Homepage http://github.com/taq/torm-elastic
Informations about the package torm-elastic
TORM-elasticsearch
This is a trait to insert ElasticSearch funcionality on TORM objects.
Installation
Change (or create, if needed) your Composer file to include it:
Usage
Just open your model and insert the trait, like:
and, after every object saving, it will be send for ElasticSearch indexing, using some rules:
- Need to insert the trait using
use TORM\ElasticSearchon the model; - Need to specify the app name using setElasticSearchIndex(
). This will be the ElasticSearch index. - After inserting the trait, a new
afterInitializemethod will be added on the model. If the model already has aafterInitializemethod, theTORM\ElasticSearchafterInitializemethod must be called explicity on its end. This is because of the way PHP traits works. -
If not specified, all the model attributes will be indexed. To define just some key attributes, we can use the
setElasticSearchValues(<attributes>)method, sending an array with the attributes, like:then only the
nameattribute will be indexed.
Searching
Then we can search using something like:
resulting in something like
Importing
When importing a new data collection, we can use the import method, like:
Getting document count
Updating a document
We can explicity update a document using:
Deleting a document
We can explicity delete a document using:
Disabling
We can disable updating documents using
and enable again sending false on the same method.
Testing
If using a TORM test enviroment (defined setting the enviroment var TORM_ENV
to test), the index name will be automatically changed to <index_name>_test.
If we want to avoid updating a document on the test enviroment, we can use