Skip to content

Commit

Permalink
add setnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Neuhaus committed May 17, 2017
1 parent 4dbc97e commit d77fcb7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Adapter/MySQLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public function __construct($configuration)
$this->configuration['socket']
);

$this->connection->query(sprintf(
'SET NAMES %s COLLATE %s',
$this->configuration['character_set'],
$this->configuration['collation']
));

$this->connection->query(sprintf('
CREATE TABLE IF NOT EXISTS `%sobjects` (
`id` int NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -106,7 +112,7 @@ protected function insertContent($id, $key, $value)
{
$query = $this->connection->prepare(sprintf('
INSERT INTO %scontents
(object, field, content, created, updated)
(object, field, content, created, updated)
VALUES(?, ?, ?, ? ,?)
',
$this->configuration['table_prefix']
Expand Down Expand Up @@ -139,7 +145,7 @@ public function getObject($objectId, $data)

$query = $this->connection->prepare(sprintf('
INSERT INTO %sobjects
(objectId, `index`, data, created, updated)
(objectId, `index`, data, created, updated)
VALUES(?, ?, ?, ?, ?)
',
$this->configuration['table_prefix']
Expand Down Expand Up @@ -197,7 +203,7 @@ public function prepareStatement($query, $options, $limit, $offset)
if (isset($options['facets'])) {
foreach ($options['facets'] as $facet => $value) {
$joins[] = sprintf(
'JOIN %s as facet_%s
'JOIN %s as facet_%s
ON rootContents.object = facet_%s.object' . chr(10),
$contentsTable,
$facet,
Expand All @@ -219,7 +225,7 @@ public function prepareStatement($query, $options, $limit, $offset)
}
$wheres[] = sprintf(
'(
MATCH(rootContents.content) AGAINST ("%1$s" IN NATURAL LANGUAGE MODE)
MATCH(rootContents.content) AGAINST ("%1$s" IN NATURAL LANGUAGE MODE)
OR rootContents.content LIKE "%%%%%1$s%%%%"
) AND rootContents.field IN (%2$s)',
$this->connection->real_escape_string($query),
Expand All @@ -239,7 +245,7 @@ public function prepareStatement($query, $options, $limit, $offset)
'SELECT %s
FROM %s as rootContents
' . implode(" \n", $joins) . '
WHERE
WHERE
' . implode(" AND ", $wheres) . '
GROUP BY %s.id
ORDER BY score DESC
Expand Down Expand Up @@ -269,7 +275,7 @@ public function getFacet($configuration)
$contentsTable = $this->configuration['table_prefix'] . 'contents';
$query = sprintf(
'SELECT field, content as value, count(id) as count
FROM %s
FROM %s
WHERE field = "%s"
GROUP BY content
',
Expand Down

0 comments on commit d77fcb7

Please sign in to comment.