@@ 22-76 (lines=55) @@ | ||
19 | * |
|
20 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html |
|
21 | */ |
|
22 | class DisMaxQuery implements BuilderInterface |
|
23 | { |
|
24 | use ParametersTrait; |
|
25 | ||
26 | /** |
|
27 | * @var BuilderInterface[] |
|
28 | */ |
|
29 | private $queries = []; |
|
30 | ||
31 | /** |
|
32 | * Initializes Dis Max query. |
|
33 | * |
|
34 | * @param array $parameters |
|
35 | */ |
|
36 | public function __construct(array $parameters = []) |
|
37 | { |
|
38 | $this->setParameters($parameters); |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * Add query. |
|
43 | * |
|
44 | * @param BuilderInterface $query |
|
45 | * |
|
46 | * @return DisMaxQuery |
|
47 | */ |
|
48 | public function addQuery(BuilderInterface $query) |
|
49 | { |
|
50 | $this->queries[] = $query; |
|
51 | ||
52 | return $this; |
|
53 | } |
|
54 | ||
55 | /** |
|
56 | * {@inheritdoc} |
|
57 | */ |
|
58 | public function getType() |
|
59 | { |
|
60 | return 'dis_max'; |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * {@inheritdoc} |
|
65 | */ |
|
66 | public function toArray() |
|
67 | { |
|
68 | $query = []; |
|
69 | foreach ($this->queries as $type) { |
|
70 | $query[] = $type->toArray(); |
|
71 | } |
|
72 | $output = $this->processArray(['queries' => $query]); |
|
73 | ||
74 | return [$this->getType() => $output]; |
|
75 | } |
|
76 | } |
|
77 |
@@ 21-81 (lines=61) @@ | ||
18 | * |
|
19 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html |
|
20 | */ |
|
21 | class SpanOrQuery implements SpanQueryInterface |
|
22 | { |
|
23 | use ParametersTrait; |
|
24 | ||
25 | /** |
|
26 | * @var SpanQueryInterface[] |
|
27 | */ |
|
28 | private $queries = []; |
|
29 | ||
30 | /** |
|
31 | * @param array $parameters |
|
32 | */ |
|
33 | public function __construct(array $parameters = []) |
|
34 | { |
|
35 | $this->setParameters($parameters); |
|
36 | } |
|
37 | ||
38 | /** |
|
39 | * Add span query. |
|
40 | * |
|
41 | * @param SpanQueryInterface $query |
|
42 | * |
|
43 | * @return $this |
|
44 | */ |
|
45 | public function addQuery(SpanQueryInterface $query) |
|
46 | { |
|
47 | $this->queries[] = $query; |
|
48 | ||
49 | return $this; |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * @return SpanQueryInterface[] |
|
54 | */ |
|
55 | public function getQueries() |
|
56 | { |
|
57 | return $this->queries; |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * {@inheritdoc} |
|
62 | */ |
|
63 | public function getType() |
|
64 | { |
|
65 | return 'span_or'; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * {@inheritdoc} |
|
70 | */ |
|
71 | public function toArray() |
|
72 | { |
|
73 | $query = []; |
|
74 | foreach ($this->queries as $type) { |
|
75 | $query['clauses'][] = $type->toArray(); |
|
76 | } |
|
77 | $output = $this->processArray($query); |
|
78 | ||
79 | return [$this->getType() => $output]; |
|
80 | } |
|
81 | } |
|
82 |