-
Notifications
You must be signed in to change notification settings - Fork 735
/
Collapse.php
60 lines (47 loc) · 1.41 KB
/
Collapse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Elastica;
use Elastica\Collapse\InnerHits;
/**
* Implementation of field collapse.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-collapse
*/
class Collapse extends Param
{
/**
* Set field to collapse.
*/
public function setFieldname(string $fieldName): self
{
return $this->setParam('field', $fieldName);
}
/**
* Set inner hits for collapsed field.
*/
public function setInnerHits(InnerHits $innerHits): self
{
return $this->setParam('inner_hits', $innerHits);
}
public function addInnerHits(InnerHits $innerHits): self
{
$hits = [];
if ($this->hasParam('inner_hits')) {
$existingInnerHits = $this->getParam('inner_hits');
$hits = $existingInnerHits instanceof InnerHits ? [$existingInnerHits] : $existingInnerHits;
}
$hits[] = $innerHits;
return $this->setParam('inner_hits', $hits);
}
public function setMaxConcurrentGroupSearches(int $groupSearches): self
{
return $this->setParam('max_concurrent_group_searches', $groupSearches);
}
public function toArray(): array
{
$data = $this->getParams();
if ($this->_rawParams) {
$data = \array_merge($data, $this->_rawParams);
}
return $this->_convertArrayable($data);
}
}