Total Complexity | 11 |
Total Lines | 102 |
Duplicated Lines | 0 % |
Coverage | 52.38% |
Changes | 0 |
1 | <?php |
||
7 | abstract class AbstractSearch |
||
8 | { |
||
9 | /** @var OngrSearch */ |
||
10 | protected $search; |
||
11 | |||
12 | /** @var string|null */ |
||
13 | private $esIndex; |
||
14 | |||
15 | /** @var string|null */ |
||
16 | private $esType; |
||
17 | |||
18 | /** |
||
19 | * AbstractDsl constructor. |
||
20 | * @param OngrSearch|null $search |
||
21 | */ |
||
22 | 22 | public function __construct(?OngrSearch $search = null) |
|
23 | { |
||
24 | 22 | $this->search = $search ?: new OngrSearch(); |
|
25 | 22 | } |
|
26 | |||
27 | /** |
||
28 | * Overwrite the default elasticsearch index |
||
29 | * |
||
30 | * @param string $index |
||
31 | * @return AbstractSearch |
||
32 | */ |
||
33 | public function esIndex(string $index) : AbstractSearch |
||
34 | { |
||
35 | $this->esIndex = $index; |
||
36 | return $this; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Get elasticsearch index |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function getEsIndex() : string |
||
45 | { |
||
46 | return $this->esIndex ?: config('laravel-elasticsearch-dsl.index'); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Overwrite the default elasticsearch type |
||
51 | * |
||
52 | * @param string $type |
||
53 | * @return AbstractSearch |
||
54 | */ |
||
55 | public function esType(string $type) : AbstractSearch |
||
56 | { |
||
57 | $this->esType = $type; |
||
58 | return $this; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Get elasticsearch type |
||
63 | * |
||
64 | * @return string|null |
||
65 | */ |
||
66 | public function getEsType() : ?string |
||
67 | { |
||
68 | return $this->esType; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get current search |
||
73 | * |
||
74 | * @return OngrSearch |
||
75 | */ |
||
76 | 13 | protected function getCurrentSearch() : OngrSearch |
|
77 | { |
||
78 | 13 | return $this->search; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * To dsl |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | 22 | public function toDsl() : array |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get search |
||
93 | * |
||
94 | * @return OngrSearch |
||
95 | */ |
||
96 | 2 | public function getSearch() : OngrSearch |
|
97 | { |
||
98 | 2 | return $this->search; |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * Get query |
||
103 | * |
||
104 | * @return BuilderInterface |
||
105 | */ |
||
106 | 11 | public function getQuery() : BuilderInterface |
|
109 | } |
||
110 | } |
||
111 |