From 6c37e35c8406cd8842b2a4ed07c5b6b9af8c1e75 Mon Sep 17 00:00:00 2001 From: KMY Date: Fri, 28 Apr 2023 09:27:27 +0900 Subject: [PATCH] Add regexp support on search accounts --- app/models/account.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 92b8947ede..c6a7cdd708 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -112,8 +112,8 @@ class Account < ApplicationRecord scope :bots, -> { where(actor_type: %w(Application Service)) } scope :groups, -> { where(actor_type: 'Group') } scope :alphabetic, -> { order(domain: :asc, username: :asc) } - scope :matches_username, ->(value) { where('lower((username)::text) LIKE lower(?)', "#{value}%") } - scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) } + scope :matches_username, ->(value) { where('lower((username)::text) ~ lower(?)', "#{value}") } + scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches_regexp("#{value}")) } scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } scope :without_unapproved, -> { left_outer_joins(:user).remote.or(left_outer_joins(:user).merge(User.approved.confirmed)) } scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) }