Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip Outer Spaces Of User Search String and Queried DB Fields #3433

Open
wants to merge 1 commit into
base: fix-for-improving-user-search
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ class User < ApplicationRecord
if date_range?(term: term)
by_date_range(:created_at, term)
else
search_pattern = "%#{term}%".squish!
search_pattern = "%#{term.strip.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
if mysql_db?
where("lower(concat_ws(' ', firstname, surname)) LIKE lower(?) OR " \
where("lower(concat_ws(' ', trim(firstname), trim(surname))) LIKE lower(?) OR " \
'lower(email) LIKE lower(?)',
search_pattern, search_pattern)
else
joins(:org)
.where("lower(firstname || ' ' || surname) LIKE lower(:search_pattern)
.where("lower(trim(firstname) || ' ' || trim(surname)) LIKE lower(:search_pattern)
OR lower(email) LIKE lower(:search_pattern)
OR lower(orgs.name) LIKE lower (:search_pattern)
OR lower(orgs.abbreviation) LIKE lower (:search_pattern) ",
Expand Down
Loading