Skip to content

Commit 1ff4bb3

Browse files
committed
Update MongoDB getIndex
1 parent 652a715 commit 1ff4bb3

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

src/Database/Drivers/MongoDB/Index.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public static function getIndexes(Collection $collection)
3131

3232
public static function getType(IndexInfo $index)
3333
{
34+
$type = "";
35+
3436
$type = static::getCommonType($index);
3537

3638
if ($index->isUnique() && !$index->isSparse() && !static::checkDescending($index)) {
@@ -57,48 +59,37 @@ public static function getType(IndexInfo $index)
5759
$type = "SPARSE_DESC";
5860
}
5961

60-
$type = static::getDefaultType($index);
61-
6262
return $type;
6363
}
6464

6565
protected static function getCommonType(IndexInfo $index)
6666
{
6767
if ($index->isText()) {
6868
return "TEXT";
69-
}
70-
71-
if ($index->is2dSphere()) {
69+
} else if ($index->is2dSphere()) {
7270
return "2DSPARSE";
73-
}
74-
75-
if ($index->isTtl()) {
71+
} else if ($index->isTtl()) {
7672
return "TTL";
77-
}
78-
79-
if ($index->isGeoHaystack()) {
73+
} else if ($index->isGeoHaystack()) {
8074
return "GEOHAYSTACK";
81-
}
82-
}
75+
} else {
76+
$name = $index->getName();
77+
$partials = explode("_", $name);
78+
$type = end($partials);
79+
if ($type == 'asc') {
80+
return "ASC";
81+
}
8382

84-
protected static function getDefaultType(IndexInfo $index)
85-
{
86-
$name = $index->getName();
87-
$partials = explode("_", $name);
88-
$type = end($partials);
89-
if ($type == 'asc') {
90-
return "ASC";
91-
}
83+
if ($type == 'index') {
84+
return "INDEX";
85+
}
9286

93-
if ($type == 'index') {
94-
return "INDEX";
95-
}
87+
if ($type == 'desc') {
88+
return "DESC";
89+
}
9690

97-
if ($type == 'desc') {
98-
return "DESC";
91+
return "";
9992
}
100-
101-
return "";
10293
}
10394

10495
protected static function checkDescending($index)

0 commit comments

Comments
 (0)