Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mysql ignore fulltext index order #154

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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