myappin/elasticsearchpredicate

ElasticSearch嵌套谓词生成器

5.6.17 2024-02-26 10:46 UTC

README

status ElasticSearchPredicate

ElasticSearchPredicate是一个简单的PHP API,它模拟Zend-Db谓词。

如果缺少某些功能或发现错误,请创建问题

安装

composer: 这里

git clone https://github.com/myappin/ElasticSearchPredicate.git

用法

添加谓词 addPredicate(PredicateInterface $predicate), andPredicate(PredicateInterface $predicate), orPredicate(PredicateInterface $predicate), and(PredicateInterface $predicate), or(PredicateInterface $predicate)

基本谓词

$_client = new Client();
$_search = $_client->search();

$_search->limit(10)->order('_uid', 'asc')->predicate->Term('name', 'SomeName')->or->Term('price', 1000);

嵌套

$_client = new Client();
$_search = $_client->search();

$_search->limit(10)->order('_uid', 'asc')->predicate->nest()->Term('name', 'SomeName')->or->Term('name', 'SomeOtherName')->unnest()->Term('price', 1000);

提升

$_client = new Client();
$_search = $_client->search();

$_search->limit(10)->order('_uid', 'asc')->predicate->andPredicate((new Term('name', 'SomeName'))->boost(2))->or->Term('name', 'SomeOtherName');
//or
$_search->limit(10)->order('_uid', 'asc')->predicate->Term('name', 'SomeName', ['boost' => 2])->or->Term('name', 'SomeOtherName');

嵌套对象、范围、评分函数等等