Fix for improving user search.
Currently Searches of users using search "firstname_<empty_spaces>_surname" will only get valid matches if the <empty_spaces> 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.
Reference: https://api.rubyonrails.org/classes/String.html#method-i-squish
Will rebase with development once @benjaminfaure has released v4.2. That should fix test failures.
Yes, if you see it elsewhere then it should also be patched. I am not going to have time to do that in the next day or so, so feel free to update in this branch if you want. :)
Yes, if you see it elsewhere then it should also be patched. I am not going to have time to do that in the next day or so, so feel free to update in this branch if you want. :)
Cool. @johnpinto1 would you want me to do that? Or would you prefer to take care of it yourself?
Yes, if you see it elsewhere then it should also be patched. I am not going to have time to do that in the next day or so, so feel free to update in this branch if you want. :)
Cool. @johnpinto1 would you want me to do that? Or would you prefer to take care of it yourself?
Please do @aaronskiba. Cheers!
Yes, if you see it elsewhere then it should also be patched. I am not going to have time to do that in the next day or so, so feel free to update in this branch if you want. :)
Cool. @johnpinto1 would you want me to do that? Or would you prefer to take care of it yourself?
Please do @aaronskiba. Cheers!
I was working on this and discovered a bit of an edge-case that complicates this PR a bit:
The issue is when the string being searched (User.firstname + User.surname, Org.name, etc.) actually has double spaces built-in.
SELECT firstname, surname
FROM users
WHERE firstname LIKE '% '
OR surname LIKE ' %';
When I execute the above query on a recent DMP Assistant DB dump from production, I get 307 returned results.
As a single example, there is a User with first name "Susan " and last name "Brown".
Searches for both "Susan Brown" (one space) or "Susan Brown" (two spaces) both return no results:
However, when I revert the changes from this PR, the User is returned when I search "Susan Brown" (two spaces):
I like the idea behind this PR, but to avoid this edge-case, I'm thinking that in addition to the search string, we'll have to apply the same .squish to the records being queried.
I like the idea behind this PR, but to avoid this edge-case, I'm thinking that in addition to the search string, we'll have to apply the same
.squishto the records being queried.
@aaronskiba Well spotted, sounds good to me.