Package Data | |
---|---|
Maintainer Username: | ErickTamayo |
Maintainer Contact: | ericktamayo@gmail.com (Erick Tamayo) |
Package Create Date: | 2014-10-29 |
Package Last Update: | 2016-08-15 |
Home Page: | |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-23 03:09:33 |
Package Statistics | |
---|---|
Total Downloads: | 84 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 45 |
Total Watchers: | 5 |
Total Forks: | 4 |
Total Open Issues: | 1 |
Stretchy in an Elasticsearch integration for Laravel 5.
Heavily Inspired by Query Builder and Schema of laravel.
Description on going.
2.0.0 - Alpha
The current documentation is at stretchy.readthedocs.org.
#Installation
###Requirements
In your composer.json, add the dependency: "tamayo/stretchy": "2.0.0"
Add the Stretchy service provider in your app.config:
'Tamayo\Stretchy\StretchyServiceProvider'
'Index' => 'Tamayo\Stretchy\Facades\Index',
'Document' => 'Tamayo\Stretchy\Facades\Document',
'Stretchy' => 'Tamayo\Stretchy\Facades\Stretchy'
php artisan config:publish tamayo/stretchy
Located in your laravel config directory: packages/tamayo/stretchy/config.php
##Quick Examples ####Create Index To create a basic index just do the following:
Index::create('foo');
If you want to specify shards and replicas:
Index::create('foo', function($index)
{
$index->shards(5);
$index->replicas(1);
});
####Delete Index
Index::delete('foo');
####Document indexing
Document::index('foo')
->type('tweet')
->id(13) // Optional (if not specified elastic will generate an unique id)
->insert([
'username' => '@ericktamayo',
'tweet' => 'Hello world!'
]);
####Update a document
Document::index('foo')
->type('tweet')
->id(13)
->update(['tweet' => 'Hello world!!!']);
####Get a document
Document::index('foo')->type('tweet')->Id(13)->get();
####Delete a document
Document::index('foo')->type('tweet')->Id(13)->delete();
###Searching
#####Match Query
Stretchy::search('foo')->match('bar', 'Stretchy')->get();
To provide additional parameters:
Stretchy::search('foo')
->match('bar', 'baz', ['operator' => 'and', 'zero_terms_query' => 'all'])
->get();
or
Stretchy::search('foo')
->match('bar', 'Stretchy', function($match)
{
$match->operator('and');
$match->zeroTermsQuery('all');
$match->cutoffFrequency(0.001);
})
->get();
#####Term Query
Stretchy::search('foo')->term('bar', 'baz')->get();
To provide additional parameters:
Stretchy::search('foo')->term('bar', 'baz', ['boost' => 2])->get();
or
Stretchy::search('foo')
->term('bar', 'baz', function($term)
{
$term->boost(2);
})
->get();
#####Bool Query
Stretchy::search('foo')
->bool(function($query)
{
$query->must(function($must)
{
$must->match('bar', 'baz');
});
$query->mustNot(function($mustNot)
{
$mustNot->match('bar', 'qux');
});
$query->should(function($should)
{
$should->match('bar', 'bah');
});
$query->minimumShouldMatch(1);
})
->get();
More examples can be found in the documentation.
###Author Erick Tamayo - ericktamayo@gmail.com - @ericktamayo
MIT