Skip to content

Commit dc79db8

Browse files
committed
Several upgrades and bug fixes
1 parent b40f8c3 commit dc79db8

File tree

10 files changed

+559
-434
lines changed

10 files changed

+559
-434
lines changed

composer.json

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
{
2-
"name": "pdphilip/elasticsearch",
3-
"description": "An Elasticsearch implementation of Laravel's Eloquent ORM",
4-
"keywords": [
5-
"laravel",
6-
"eloquent",
7-
"elasticsearch",
8-
"elastic",
9-
"database",
10-
"model"
11-
],
12-
"homepage": "https://github.com/pdphilip/laravel-elasticsearch",
13-
"authors": [
14-
{
15-
"name": "David Philip",
16-
"homepage": "https://github.com/pdphilip"
17-
}
18-
],
19-
"license": "MIT",
20-
"require": {
21-
"illuminate/support": "^5.8|^6.0",
22-
"illuminate/container": "^5.8|^6.0",
23-
"illuminate/database": "^5.8|^6.0",
24-
"illuminate/events": "^5.8|^6.0",
25-
"elasticsearch/elasticsearch": "8.7",
26-
"php-http/guzzle7-adapter": "^1.0"
27-
},
28-
"autoload": {
29-
"psr-4": {
30-
"PDPhilip\\Elasticsearch\\": "src/"
31-
}
32-
},
33-
"extra": {
34-
"laravel": {
35-
"providers": [
36-
"PDPhilip\\Elasticsearch\\ElasticServiceProvider"
37-
]
38-
}
39-
},
40-
"config": {
41-
"allow-plugins": {
42-
"php-http/discovery": true
43-
}
2+
"name": "pdphilip/elasticsearch",
3+
"description": "An Elasticsearch implementation of Laravel's Eloquent ORM",
4+
"keywords": [
5+
"laravel",
6+
"eloquent",
7+
"elasticsearch",
8+
"elastic",
9+
"database",
10+
"model"
11+
],
12+
"homepage": "https://github.com/pdphilip/laravel-elasticsearch",
13+
"authors": [
14+
{
15+
"name": "David Philip",
16+
"homepage": "https://github.com/pdphilip"
4417
}
18+
],
19+
"license": "MIT",
20+
"require": {
21+
"illuminate/support": "^5.8|^6.0",
22+
"illuminate/container": "^5.8|^6.0",
23+
"illuminate/database": "^5.8|^6.0",
24+
"illuminate/events": "^5.8|^6.0",
25+
"elasticsearch/elasticsearch": "8.10",
26+
"php-http/guzzle7-adapter": "^1.0"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"PDPhilip\\Elasticsearch\\": "src/"
31+
}
32+
},
33+
"extra": {
34+
"laravel": {
35+
"providers": [
36+
"PDPhilip\\Elasticsearch\\ElasticServiceProvider"
37+
]
38+
}
39+
},
40+
"config": {
41+
"allow-plugins": {
42+
"php-http/discovery": true
43+
}
44+
}
4545
}

src/Connection.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace PDPhilip\Elasticsearch;
44

5+
use Elastic\Elasticsearch\Client;
56
use PDPhilip\Elasticsearch\DSL\Bridge;
67
use Elastic\Elasticsearch\ClientBuilder;
78
use Illuminate\Database\Connection as BaseConnection;
8-
use Illuminate\Support\Arr;
99
use Illuminate\Support\Str;
10-
use InvalidArgumentException;
11-
use phpDocumentor\Reflection\Types\Scalar;
1210
use 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

Comments
 (0)