Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fe3bff

Browse files
author
Krecu Eugen
committed
PostgresSQL uuid field dont have LOWER function
1 parent d26542a commit 1fe3bff

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

Search/QueryBuilder.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,27 @@ public function createSearchQueryBuilder(array $entityConfig, $searchQuery, $sor
9292
// adding '0' turns the string into a numeric value
9393
$queryParameters['exact_query'] = 0 + $searchQuery;
9494
} elseif ($isTextField) {
95-
$searchQuery = strtolower($searchQuery);
9695

97-
$queryBuilder->orWhere(sprintf('LOWER(entity.%s) LIKE :fuzzy_query', $name));
98-
$queryParameters['fuzzy_query'] = '%'.$searchQuery.'%';
99-
100-
$queryBuilder->orWhere(sprintf('LOWER(entity.%s) IN (:words_query)', $name));
101-
$queryParameters['words_query'] = explode(' ', $searchQuery);
96+
/**
97+
* PostgresSQL uuid field dont have LOWER function
98+
*/
99+
if ($metadata['dataType'] == 'guid') {
100+
// insert to query if search query value is valid guid
101+
if (preg_match('/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/', $name)) {
102+
$queryBuilder->orWhere(sprintf('entity.%s IN (:words_query)', $name));
103+
$queryParameters['words_query'] = explode(' ', $searchQuery);
104+
}
105+
} else {
106+
107+
// mb_strtolower for cyrillic support
108+
$searchQuery = mb_strtolower($searchQuery);
109+
110+
$queryBuilder->orWhere(sprintf('LOWER(entity.%s) LIKE :fuzzy_query', $name));
111+
$queryParameters['fuzzy_query'] = '%' . $searchQuery . '%';
112+
113+
$queryBuilder->orWhere(sprintf('LOWER(entity.%s) IN (:words_query)', $name));
114+
$queryParameters['words_query'] = explode(' ', $searchQuery);
115+
}
102116
}
103117
}
104118

0 commit comments

Comments
 (0)