Skip to content

Commit 7474c69

Browse files
committed
Schema features update
- Updated get Mappings/Settings to resolve to local index name - Added model methods for schema processing
1 parent a288527 commit 7474c69

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

src/Eloquent/Builder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class Builder extends BaseEloquentBuilder
4141
'matrix',
4242
'query',
4343
'rawSearch',
44+
'getIndexSettings',
45+
'getIndexMappings',
46+
'deleteIndexIfExists',
47+
'deleteIndex',
48+
'truncate',
49+
'indexExists',
50+
'createIndex',
4451
];
4552

4653

src/Query/Builder.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,32 @@ public function deleteIndexIfExists()
770770

771771
}
772772

773+
public function getIndexMappings()
774+
{
775+
return Schema::getMappings($this->index);
776+
}
777+
778+
public function getIndexSettings()
779+
{
780+
return Schema::getSettings($this->index);
781+
}
782+
783+
public function indexExists()
784+
{
785+
return Schema::hasIndex($this->index);
786+
}
787+
788+
public function createIndex()
789+
{
790+
if (!$this->indexExists()) {
791+
$this->connection->indexCreate($this->index);
792+
793+
return true;
794+
}
795+
796+
return false;
797+
}
798+
773799
public function rawSearch(array $bodyParams)
774800
{
775801
$find = $this->connection->searchRaw($bodyParams);
@@ -888,7 +914,7 @@ public function search($text, $columns = [], $returnLazy = false)
888914

889915
return new Collection($data);
890916
} else {
891-
throw new RuntimeException('Error: '.$find->errorMessage);
917+
throw new RuntimeException('Error: '.$result->errorMessage);
892918
}
893919
}
894920

src/Schema/Builder.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@ public function __construct(Connection $connection)
2020
// View Index Meta
2121
//----------------------------------------------------------------------
2222

23-
public function getIndices($all = false)
23+
public function getIndices($includeSystem = false)
2424
{
25-
return $this->connection->getIndices($all);
25+
return $this->connection->getIndices($includeSystem);
2626
}
2727

28-
public function getMappings($index)
28+
public function getMappings($index, $forceIndexName = false)
2929
{
30+
if (!$forceIndexName) {
31+
$index = $this->connection->setIndex($index);
32+
}
33+
3034
return $this->connection->indexMappings($index);
3135
}
3236

33-
public function getSettings($index)
37+
public function getSettings($index, $forceIndexName = false)
3438
{
39+
if (!$forceIndexName) {
40+
$index = $this->connection->setIndex($index);
41+
}
42+
3543
return $this->connection->indexSettings($index);
3644
}
3745

src/Schema/Schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8-
* @method static Builder getIndices(bool $all = null)
9-
* @method static Builder getMappings(string $index)
10-
* @method static Builder getSettings(string $index)
8+
* @method static Builder getIndices(bool $includeSystem = false)
9+
* @method static Builder getMappings(string $index, $forceIndexName = false)
10+
* @method static Builder getSettings(string $index, $forceIndexName = false)
1111
* @method static Builder create(string $index, \Closure $callback)
1212
* @method static Builder createIfNotExists(string $index, \Closure $callback)
1313
* @method static Builder reIndex(string $from, string $to)

0 commit comments

Comments
 (0)