22
33namespace PDPhilip \Elasticsearch ;
44
5+ use Elastic \Elasticsearch \Client ;
56use PDPhilip \Elasticsearch \DSL \Bridge ;
67use Elastic \Elasticsearch \ClientBuilder ;
78use Illuminate \Database \Connection as BaseConnection ;
8- use Illuminate \Support \Arr ;
99use Illuminate \Support \Str ;
10- use InvalidArgumentException ;
11- use phpDocumentor \Reflection \Types \Scalar ;
1210use RuntimeException ;
1311
1412
@@ -39,18 +37,23 @@ public function __construct(array $config)
3937
4038 }
4139
42- public function getIndexPrefix ()
40+ public function getIndexPrefix (): string
4341 {
4442 return $ this ->indexPrefix ;
4543 }
4644
45+ public function setIndexPrefix ($ newPrefix ): void
46+ {
47+ $ this ->indexPrefix = $ newPrefix ;
48+ }
4749
48- public function getTablePrefix ()
50+
51+ public function getTablePrefix (): string
4952 {
5053 return $ this ->getIndexPrefix ();
5154 }
5255
53- public function setIndex ($ index )
56+ public function setIndex ($ index ): string
5457 {
5558 $ this ->index = $ index ;
5659 if ($ this ->indexPrefix ) {
@@ -67,7 +70,7 @@ public function getSchemaGrammar()
6770 return new Schema \Grammar ($ this );
6871 }
6972
70- public function getIndex ()
73+ public function getIndex (): string
7174 {
7275 return $ this ->index ;
7376 }
@@ -77,12 +80,14 @@ public function setMaxSize($value)
7780 $ this ->maxSize = $ value ;
7881 }
7982
83+
8084 public function table ($ table , $ as = null )
8185 {
82- return $ this ->setIndex ($ table );
86+ $ query = new Query \Builder ($ this , new Query \Processor ());
87+
88+ return $ query ->from ($ table );
8389 }
8490
85-
8691 /**
8792 * @inheritdoc
8893 */
@@ -104,7 +109,7 @@ public function disconnect()
104109 /**
105110 * @inheritdoc
106111 */
107- public function getDriverName ()
112+ public function getDriverName (): string
108113 {
109114 return 'elasticsearch ' ;
110115 }
@@ -138,7 +143,7 @@ protected function getDefaultSchemaGrammar()
138143 // Connection Builder
139144 //----------------------------------------------------------------------
140145
141- protected function buildConnection ()
146+ protected function buildConnection (): Client
142147 {
143148 $ type = config ('database.connections.elasticsearch.auth_type ' ) ?? null ;
144149 $ type = strtolower ($ type );
@@ -150,7 +155,7 @@ protected function buildConnection()
150155
151156 }
152157
153- protected function _httpConnection ()
158+ protected function _httpConnection (): Client
154159 {
155160 $ hosts = config ('database.connections.elasticsearch.hosts ' ) ?? null ;
156161 $ username = config ('database.connections.elasticsearch.username ' ) ?? null ;
@@ -167,7 +172,7 @@ protected function _httpConnection()
167172 return $ cb ->build ();
168173 }
169174
170- protected function _cloudConnection ()
175+ protected function _cloudConnection (): Client
171176 {
172177 $ cloudId = config ('database.connections.elasticsearch.cloud_id ' ) ?? null ;
173178 $ username = config ('database.connections.elasticsearch.username ' ) ?? null ;
@@ -195,6 +200,10 @@ protected function _cloudConnection()
195200
196201 public function __call ($ method , $ parameters )
197202 {
203+ if (!$ this ->index ) {
204+ $ this ->index = $ this ->indexPrefix .'* ' ;
205+ }
206+
198207 $ bridge = new Bridge ($ this ->client , $ this ->index , $ this ->maxSize );
199208
200209 return $ bridge ->{'process ' .Str::studly ($ method )}(...$ parameters );
0 commit comments