Package Data | |
---|---|
Maintainer Username: | almeida |
Maintainer Contact: | arnold@floatingpoints.com.au (Arnold Almeida) |
Package Create Date: | 2015-03-07 |
Package Last Update: | 2015-04-10 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-18 03:05:53 |
Package Statistics | |
---|---|
Total Downloads: | 24 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 1 |
Total Forks: | 1 |
Total Open Issues: | 0 |
I need to improve search. Currently using mongob, 2dspheres etc.
Bring on Elasticsearch. Basically just a wrapper for the offical client.
http://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
require : {
"almeida/laravel-elasticsearch" : "dev-master"
}
Extend the abstract ElasticDocument
so you get some easy CRUD.
Let's assume we are working with movies.
/**
* Acme\Search\MovieDocument
*/
class MovieDocument extends \Almeida\LaravelElasticSearch\ElasticDocumentAbstract
{
protected $index = 'movie_cluster';
protected $type = 'movies';
public function setId($movie) {
return $movie->id;
}
}
Create an index.
Assuming you have already a working fractal/transformer
$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.
$document = new \Acme\Search\MovieDocument();
$document->delete($movie->id);
$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");
Promise to work on it over the next few days.
$movieTitle = 'Scarface';
$document->basicSearch($movieTitle);
think about this more
Move search, stats, and aggerates to Traits so we only use them on applicable documents
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
This fixed it for now...
The correct way to access is actually through, http://127.0.0.1:9200
Will work it out when i sort out nicer config etc.
How is it calculated ?
https://www.elastic.co/downloads/marvel
I accept bitcoin tips. [18tEqEUnyJaqvKh3CCNAAai9seztLb3Tw9].
They should too! Come on its going to be a thing.
MIT