aqarmap / elastic-repository
弹性搜索活动仓库包
Requires
- ruflin/elastica: ^5.2
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2024-09-15 05:02:50 UTC
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);
TODO
- 缓存支持
贡献
有关详细信息,请参阅 CONTRIBUTING
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件