fixed 搜索用户时过虑表情字符

This commit is contained in:
xxq250 2023-03-09 16:02:50 +08:00
parent e9a152032c
commit 6e16a9397c
2 changed files with 4 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class Owner < ApplicationRecord
has_many :applied_transfer_projects, dependent: :destroy
scope :like, lambda { |keywords|
# 表情处理
keywords = keywords.each_char.select { |c| c.bytes.first < 240 }.join('')
sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search "
where(sql, :search => "%#{keywords.strip}%") unless keywords.blank?
}

View File

@ -185,6 +185,8 @@ class User < Owner
# Groups and active users
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
scope :like, lambda { |keywords|
# 表情处理
keywords = keywords.each_char.select { |c| c.bytes.first < 240 }.join('')
sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search"
where(sql, :search => "%#{keywords.strip}%") unless keywords.blank?
}