From 4e6995e27d533994ed9f3733b017afee2d8cdd69 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Wed, 10 Apr 2024 11:28:40 +0100 Subject: [PATCH] Fix for improving user search. Currently Searches of users using search "firstname__surname" will only get valid matches if the __ is a single empty space. Change: The search term string is squished to remove extra empty spaces. As a result search terms like "Jill Bloggs" (one space between) and "Jill Bloggs" (more than one space between) will both return the same results. --- CHANGELOG.md | 5 +++++ app/models/user.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aeeb4e2f3..971a69f417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.2.1 + +### Changed +- A minor change to search that removes extra empty sppaces between words to allow user search to work if there are more than one space between firstname and surname, e,g., "Jill Blogss" and "Jill Bloggs" should return same results. + ## v4.2.0 **Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.** diff --git a/app/models/user.rb b/app/models/user.rb index c3ff357961..e8afb3f93e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -138,7 +138,7 @@ class User < ApplicationRecord if date_range?(term: term) by_date_range(:created_at, term) else - search_pattern = "%#{term}%" + search_pattern = "%#{term}%".squish! # MySQL does not support standard string concatenation and since concat_ws # or concat functions do not exist for sqlite, we have to come up with this # conditional