aqarmap / elastic
ElasticSearch活动仓库包
v1.11.1
2024-05-14 00:12 UTC
Requires
- ruflin/elastica: ^6.0
Requires (Dev)
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()
方法添加查询的主要排序标准:默认情况下,当添加得分函数时按得分排序
// 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
- caching support
贡献
有关详细信息,请参阅CONTRIBUTING
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。