mustafah15 / elastic-repository
此包已被 废弃 并不再维护。未建议替代包。
弹性搜索活动仓库包
1.0
2017-12-30 14:52 UTC
Requires
- ruflin/elastica: ^5.2
Requires (Dev)
- phpunit/phpunit: ^6.1
README
🎉 Elasticsearch 仓库包
Elasticsearch 仓库包是为 Elasticsearch 实现的简单、智能的活动仓库。
🔥 特性
- 在您的 Elasticsearch 索引和类型上提供活动仓库模式。
- 将查询构建器引入 Elasticsearch 仓库。
- 在具有大型业务逻辑的系统上构建 Elasticsearch 查询时,最小化代码行数。
- 防止代码重复。
- 减少潜在的编程错误。
❕ 安装
通过 composer 获取
composer require mustafah15/elastic-repository
集成
Elasticsearch 仓库 包是框架无关的,因此可以轻松地与您的首选框架原生集成或一起使用。
✨ 使用
- 将 ElasticRepository 类扩展为您的类型或索引的仓库。
class schoolsRepository extends ElasticRepository { // method contains some bussiness logic public function returnQueryWherename() { $this->where('name', 'EGSchool', 0.5)->getResultQuery(); } }
📋 文档
ElasticRepository
当您扩展 ElasticRepository
类时,您将拥有各种功能
setIndex()
, setType()
setIndex()
和 setType()
方法用于将索引名称和类型名称设置到仓库中
setSort()
setSort()
方法添加查询的主要排序标准:默认情况下,添加评分函数时使用 _score 排序
// pass field name to sort by $queryBuilder->setSort('fieldName');
setOrder()
setOrder()
方法用于指定排序方向
$queryBuilder->setSort('fieldName')->setOrder('desc');
setTransformer($transformer)
setTransformer($transformer)
用于添加结果转换器,必须实现 TransformerContract
get()
使用查询构建器构建查询后,使用 get()
方法获取结果
getResultWithScore()
使用 getResultWithScore($scoreFunction)
方法添加评分函数后获取结果:将 Query\FunctionScore $functionScore
作为参数应用于您的结果
getResultQuery()
getResultQuery()
返回查询对象
getResultQueryWithScore($scoreFunction)
将Query\FunctionScore $functionScore
作为参数用于对查询进行评分
QueryBuilder
每个ElasticRepository类都有自己的查询构建器,它包含许多操作和功能,您可以使用。
where()
、whereNot()
where()
和whereNot()
方法向主过滤器添加必须和不需要的条件
//attribute paramter then the expected value and optional value for the field boost $queryBuilder->where($attribute, $value = null, $boost = 1.0);
whereIn()
、whereNotIn()
whereIn()
和whereNotIn()
方法向主过滤器添加范围
//attribute paramter then a optional value for the fields from and to $queryBuilder->whereIn($attribute, $from = '', $to = '');
exist('fieldName')
$queryBuilder->exist('fieldName');
match($attribute, $keyword)
$queryBuilder->match('fieldName', $keywordToMatch);
待办事项
- 添加剩余的CRUD操作(插入、更新)
- 缓存支持
贡献
请参阅CONTRIBUTING以获取详细信息。
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。