Skip to content

Commit

Permalink
Merge pull request #154 from utopia-php/fix-fulltext-order
Browse files Browse the repository at this point in the history
fix: mysql ignore fulltext index order
  • Loading branch information
TorstenDittmann authored Jul 19, 2022
2 parents f9b2596 + 27b902b commit 227b3ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 56 deletions.
21 changes: 1 addition & 20 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function createCollection(string $name, array $attributes = [], array $in

foreach ($indexes as $key => $index) {
$indexId = $this->filter($index->getId());
$indexType = $this->getSQLIndexType($index->getAttribute('type'));
$indexType = $index->getAttribute('type');

$indexAttributes = $index->getAttribute('attributes');
foreach ($indexAttributes as $nested => $attribute) {
Expand Down Expand Up @@ -1335,7 +1335,6 @@ protected function getSQLType(string $type, int $size, bool $signed = true): str
}

return "VARCHAR({$size})";
break;

case Database::VAR_INTEGER: // We don't support zerofill: https://stackoverflow.com/a/5634147/2299554
$signed = ($signed) ? '' : ' UNSIGNED';
Expand All @@ -1345,24 +1344,19 @@ protected function getSQLType(string $type, int $size, bool $signed = true): str
}

return 'INT' . $signed;
break;

case Database::VAR_FLOAT:
$signed = ($signed) ? '' : ' UNSIGNED';
return 'FLOAT' . $signed;
break;

case Database::VAR_BOOLEAN:
return 'TINYINT(1)';
break;

case Database::VAR_DOCUMENT:
return 'CHAR(255)';
break;

default:
throw new Exception('Unknown Type');
break;
}
}

Expand Down Expand Up @@ -1391,11 +1385,9 @@ protected function getSQLCondition(string $attribute, string $operator, string $
$value = "'{$value}*'";

return 'MATCH(' . $attribute . ') AGAINST(' . $this->getPDO()->quote($value) . ' IN BOOLEAN MODE)';
break;

default:
return $attribute . ' ' . $this->getSQLOperator($operator) . ' ' . $placeholder; // Using `attrubute_` to avoid conflicts with custom names;
break;
}
}

Expand All @@ -1411,31 +1403,24 @@ protected function getSQLOperator(string $operator): string
switch ($operator) {
case Query::TYPE_EQUAL:
return '=';
break;

case Query::TYPE_NOTEQUAL:
return '!=';
break;

case Query::TYPE_LESSER:
return '<';
break;

case Query::TYPE_LESSEREQUAL:
return '<=';
break;

case Query::TYPE_GREATER:
return '>';
break;

case Query::TYPE_GREATEREQUAL:
return '>=';
break;

default:
throw new Exception('Unknown Operator:' . $operator);
break;
}
}

Expand All @@ -1452,19 +1437,15 @@ protected function getSQLIndexType(string $type): string
case Database::INDEX_KEY:
case Database::INDEX_ARRAY:
return 'INDEX';
break;

case Database::INDEX_UNIQUE:
return 'UNIQUE INDEX';
break;

case Database::INDEX_FULLTEXT:
return 'FULLTEXT INDEX';
break;

default:
throw new Exception('Unknown Index Type:' . $type);
break;
}
}

Expand Down
38 changes: 2 additions & 36 deletions src/Database/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@ protected function getIndexTypeForReadPermission(): string
return Database::INDEX_ARRAY;
}

/**
* Get SQL Index Type
*
* @param string $type
*
* @return string
*/
protected function getSQLIndexType(string $type): string
{
switch ($type) {
case Database::INDEX_KEY:
$type = 'INDEX';
break;

case Database::INDEX_ARRAY:
$type = 'INDEX';
break;

case Database::INDEX_UNIQUE:
$type = 'UNIQUE INDEX';
break;

case Database::INDEX_FULLTEXT:
$type = 'FULLTEXT INDEX';
break;

default:
throw new Exception('Unknown Index Type:' . $type);
break;
}

return $type;
}

/**
* Get SQL Index
*
Expand All @@ -81,8 +47,8 @@ protected function getSQLIndex(string $collection, string $id, string $type, arr
case Database::INDEX_ARRAY:
$type = 'INDEX';

foreach ($attributes as $key => &$value) {
$value = '(CAST(' . $value . ' AS char(255) ARRAY))';
foreach ($attributes as $key => $value) {
$attributes[$key] = '(CAST(' . $value . ' AS char(255) ARRAY))';
}
break;

Expand Down

0 comments on commit 227b3ca

Please sign in to comment.