roadmap icon indicating copy to clipboard operation
roadmap copied to clipboard

Fix for improving user search.

Open johnpinto1 opened this issue 1 year ago • 6 comments

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

johnpinto1 avatar Apr 10 '24 12:04 johnpinto1

Will rebase with development once @benjaminfaure has released v4.2. That should fix test failures.

johnpinto1 avatar Apr 10 '24 12:04 johnpinto1

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. :)

briri avatar Jun 17 '24 20:06 briri

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?

aaronskiba avatar Jun 24 '24 21:06 aaronskiba

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!

johnpinto1 avatar Jun 25 '24 08:06 johnpinto1

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: Screenshot from 2024-06-26 10-44-19 Screenshot from 2024-06-26 10-44-28

However, when I revert the changes from this PR, the User is returned when I search "Susan Brown" (two spaces): Screenshot from 2024-06-26 10-45-00

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.

aaronskiba avatar Jun 26 '24 16:06 aaronskiba

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.

@aaronskiba Well spotted, sounds good to me.

johnpinto1 avatar Jun 27 '24 08:06 johnpinto1