1<?php
2
3namespace Elastica\Query;
4
5/**
6 * geo_shape query for pre-indexed shapes.
7 *
8 * Query pre-indexed shape definitions
9 *
10 * @author Bennie Krijger <benniekrijger@gmail.com>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
13 */
14class GeoShapePreIndexed extends AbstractGeoShape
15{
16    /**
17     * elasticsearch id of the pre-indexed shape.
18     *
19     * @var string
20     */
21    protected $_indexedId;
22
23    /**
24     *  elasticsearch index of the pre-indexed shape.
25     *
26     * @var string
27     */
28    protected $_indexedIndex;
29
30    /**
31     *  elasticsearch path/field name of the pre-indexed shape.
32     *
33     * @var string
34     */
35    protected $_indexedPath;
36
37    /**
38     * Construct geo_shape query with a pre-indexed shape.
39     *
40     * @param string $path         The path/field of the shape searched
41     * @param string $indexedId    Id of the pre-indexed shape
42     * @param string $indexedIndex Index of the pre-indexed shape
43     * @param string $indexedPath  Path of the pre-indexed shape
44     */
45    public function __construct(
46        string $path,
47        string $indexedId,
48        string $indexedIndex,
49        string $indexedPath
50    ) {
51        $this->_path = $path;
52        $this->_indexedId = $indexedId;
53        $this->_indexedIndex = $indexedIndex;
54        $this->_indexedPath = $indexedPath;
55    }
56
57    /**
58     * {@inheritdoc}
59     */
60    public function toArray(): array
61    {
62        return [
63            'geo_shape' => [
64                $this->_path => [
65                    'indexed_shape' => [
66                        'id' => $this->_indexedId,
67                        'index' => $this->_indexedIndex,
68                        'path' => $this->_indexedPath,
69                    ],
70                    'relation' => $this->_relation,
71                ],
72            ],
73        ];
74    }
75}
76