2017 © Pedro Peláez
 

library laravel-elasticsearch

Laravel 4.2+ wrapper for ElasticSearch

image

almeida/laravel-elasticsearch

Laravel 4.2+ wrapper for ElasticSearch

  • Friday, April 10, 2015
  • by almeida
  • Repository
  • 1 Watchers
  • 1 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Preamble

I need to improve search. Currently using mongob, 2dspheres etc., (*1)

Bring on Elasticsearch. Basically just a wrapper for the offical client., (*2)

http://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html, (*3)

Afternoon hack
  • Trying to put togeter a nice package so we can use ElasticSearch easily
  • Should play well with league/fractal
  • Should play well with illuminate/collections
  • Should play well with fractal/item
  • Should play well with fractal/resources
  • etc..

Install via Composer

require : {
    "almeida/laravel-elasticsearch" : "dev-master"
}

Step 1

Extend the abstract ElasticDocument so you get some easy CRUD., (*4)

Let's assume we are working with movies., (*5)


/** * Acme\Search\MovieDocument */ class MovieDocument extends \Almeida\LaravelElasticSearch\ElasticDocumentAbstract { protected $index = 'movie_cluster'; protected $type = 'movies'; public function setId($movie) { return $movie->id; } }

Creating / Updating an index

Create an index., (*6)

Assuming you have already a working fractal/transformer, (*7)


$options = []; $options['transformer'] = 'Acme\MovieTransformer'; $document = new \Acme\Search\MovieDocument($options); $document->setBody($movie); $document->index(); // or $document->create(); // or $document->update(); // OR $document = new \Acme\Search\MovieDocument(); $document->setBody($movie); $document->setTransformer('Acme\MovieTransformer'); $document->index();

Deleting an index (@todo)

Deleting an index., (*8)


$document = new \Acme\Search\MovieDocument(); $document->delete($movie->id);

Indexing en masse in the Console


$n = 0; Movie::chunk(100, function($movies) use(&$n) { foreach ($movies as $i => $movie) { $document = new \Acme\Search\MovieDocument(); $document->setBody($movie); $document->setTransformer('Acme\MovieTransformer'); $document->index(); $this->info("Indexed : {$movie->title}"); $n++; } }); $this->info("Indexed [{$n}] movies");

Searching (WIP)

Promise to work on it over the next few days., (*9)


$movieTitle = 'Scarface'; $document->basicSearch($movieTitle);

Todo

  • think about this more, (*10)

  • Move search, stats, and aggerates to Traits so we only use them on applicable documents, (*11)

GOTCHAS

Deving locally on OSX i couldnt get the client to connect to elasticsearch even though i could access it in the browser at http://localhost:9200, (*12)

This fixed it for now..., (*13)

  • http://benjaminknofe.com/blog/2015/02/19/no-connection-on-localhost-to-elasticsearch-on-osx/

The correct way to access is actually through, http://127.0.0.1:9200, (*14)

Will work it out when i sort out nicer config etc., (*15)

Required reading

  • http://www.elastic.co/guide/en/elasticsearch/guide/current/
  • http://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html
Relevance

How is it calculated ?, (*16)

  • http://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-intro.html
Monitoring elasticsearch using Marvel (dev)

https://www.elastic.co/downloads/marvel, (*17)

Thanks for the notes

  • http://www.slideshare.net/bencorlett/discovering-elasticsearch
  • http://blog.madewithlove.be/post/integrating-elasticsearch-with-your-laravel-app/
  • http://blog.madewithlove.be/post/elasticsearch-aggregations/
  • https://www.youtube.com/watch?v=waTWeJeFp4A
  • https://www.youtube.com/watch?v=7FLXjgB0PQI
  • http://laravel.com/docs/4.2/eloquent#model-observers
  • https://www.youtube.com/watch?v=GrdzX9BNfkg

I accept bitcoin tips. [18tEqEUnyJaqvKh3CCNAAai9seztLb3Tw9]., (*18)

They should too! Come on its going to be a thing., (*19)

LICENSE

MIT, (*20)

The Versions

10/04 2015

dev-master

9999999-dev https://github.com/arnold-almeida/laravel-elasticsearch

Laravel 4.2+ wrapper for ElasticSearch

  Sources   Download

MIT

The Requires

 

laravel elasticsearch

10/04 2015
07/03 2015