From 14592fa4671a1d5d3e98dee2c4ad66046c698e88 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Fri, 4 Dec 2020 16:27:45 +0100 Subject: [PATCH] FEAT #15401 TIME 1:30 Search Format Registered mail number if necessary --- src/app/search/controllers/SearchController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/search/controllers/SearchController.php b/src/app/search/controllers/SearchController.php index e0c61da3da0..884e43be277 100644 --- a/src/app/search/controllers/SearchController.php +++ b/src/app/search/controllers/SearchController.php @@ -327,17 +327,21 @@ class SearchController if (!empty($body['meta']) && !empty($body['meta']['values']) && is_string($body['meta']['values'])) { if ($body['meta']['values'][0] == '"' && $body['meta']['values'][strlen($body['meta']['values']) - 1] == '"') { $quick = trim($body['meta']['values'], '"'); - $quickWhere = "subject = ? OR alt_identifier = ? OR barcode = ?"; + $quickWhere = "subject = ? OR replace(alt_identifier, ' ', '') = ? OR barcode = ?"; $quickWhere .= " OR res_id in (select res_id_master from res_attachments where (title = ? OR identifier = ?) and status in ('TRA', 'A_TRA', 'FRZ'))"; + + $whiteStrippedChrono = str_replace(' ', '', $quick); + $args['searchData'] = array_merge($args['searchData'], [$quick, $whiteStrippedChrono, $quick, $quick, $quick]); + if (ctype_digit($quick)) { $quickWhere .= ' OR res_id = ?'; $args['searchData'][] = $quick; } $args['searchWhere'][] = '(' . $quickWhere . ')'; - $args['searchData'] = array_merge($args['searchData'], [$quick, $quick, $quick, $quick, $quick]); } else { - $fields = ['subject', 'alt_identifier', 'barcode']; + $fields = ['subject', 'replace(alt_identifier, \' \', \'\')', 'barcode']; + $fields = AutoCompleteController::getInsensitiveFieldsForRequest(['fields' => $fields]); $requestDataDocument = AutoCompleteController::getDataForRequest([ 'search' => $body['meta']['values'], @@ -416,8 +420,9 @@ class SearchController } } if (!empty($body['chrono']) && !empty($body['chrono']['values']) && is_string($body['chrono']['values'])) { - $args['searchWhere'][] = '(alt_identifier ilike ? OR res_id in (select res_id_master from res_attachments where identifier ilike ? and status in (\'TRA\', \'A_TRA\', \'FRZ\')))'; - $args['searchData'][] = "%{$body['chrono']['values']}%"; + $args['searchWhere'][] = '(replace(alt_identifier, \' \', \'\') ilike ? OR res_id in (select res_id_master from res_attachments where identifier ilike ? and status in (\'TRA\', \'A_TRA\', \'FRZ\')))'; + $whiteStrippedChrono = str_replace(' ', '', $body['chrono']['values']); + $args['searchData'][] = "%{$whiteStrippedChrono}%"; $args['searchData'][] = "%{$body['chrono']['values']}%"; } if (!empty($body['barcode']) && !empty($body['barcode']['values']) && is_string($body['barcode']['values'])) { -- GitLab