tamayo / stretchy
此包的最新版本(2.0.0)没有提供许可证信息。
Laravel 5.0 的 Elastic Search 集成
2.0.0
2016-07-28 02:15 UTC
Requires
- php: >=5.4.0
- elasticsearch/elasticsearch: ~1.0
- illuminate/support: 5.2.*
Requires (Dev)
- mockery/mockery: 0.9.2
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-21 03:49:08 UTC
README
Stretchy 是 Laravel 5 的一个 Elasticsearch 集成。
深受 Laravel 的查询构建器和模式启发。
描述进行中。
版本
2.0.0 - Alpha
文档
当前文档位于 stretchy.readthedocs.org。
##安装
###要求
- PHP 5.5.9+
使用 Composer 安装
-
在你的 composer.json 中添加依赖:
"tamayo/stretchy": "2.0.0"
-
在你的 app.config 中添加 Stretchy 服务提供者
'Tamayo\Stretchy\StretchyServiceProvider'
- 添加以下别名
'Index' => 'Tamayo\Stretchy\Facades\Index', 'Document' => 'Tamayo\Stretchy\Facades\Document', 'Stretchy' => 'Tamayo\Stretchy\Facades\Stretchy'
- (可选)如果你想覆盖默认配置
php artisan config:publish tamayo/stretchy
位于你的 Laravel 配置目录: packages/tamayo/stretchy/config.php
##快速示例 ####创建索引 要创建一个基本索引,只需执行以下操作
Index::create('foo');
如果你想指定分片和副本
Index::create('foo', function($index) { $index->shards(5); $index->replicas(1); });
####删除索引
Index::delete('foo');
####文档索引
Document::index('foo') ->type('tweet') ->id(13) // Optional (if not specified elastic will generate an unique id) ->insert([ 'username' => '@ericktamayo', 'tweet' => 'Hello world!' ]);
####更新文档
Document::index('foo') ->type('tweet') ->id(13) ->update(['tweet' => 'Hello world!!!']);
####获取文档
Document::index('foo')->type('tweet')->Id(13)->get();
####删除文档
Document::index('foo')->type('tweet')->Id(13)->delete();
###搜索
#####匹配查询
Stretchy::search('foo')->match('bar', 'Stretchy')->get();
提供额外的参数
Stretchy::search('foo') ->match('bar', 'baz', ['operator' => 'and', 'zero_terms_query' => 'all']) ->get();
或
Stretchy::search('foo') ->match('bar', 'Stretchy', function($match) { $match->operator('and'); $match->zeroTermsQuery('all'); $match->cutoffFrequency(0.001); }) ->get();
#####术语查询
Stretchy::search('foo')->term('bar', 'baz')->get();
提供额外的参数
Stretchy::search('foo')->term('bar', 'baz', ['boost' => 2])->get();
或
Stretchy::search('foo') ->term('bar', 'baz', function($term) { $term->boost(2); }) ->get();
#####布尔查询
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();
更多示例可以在 文档 中找到。
路线图
- 文档
- 使库独立于 Laravel 组件
- 添加 PutMapping API
###作者 Erick Tamayo - ericktamayo@gmail.com - @ericktamayo
许可证
MIT