Browse Source

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

pull/343/head
xxq250 3 years ago
parent
commit
d993df7df4
2 changed files with 4 additions and 0 deletions
  1. +2
    -0
      app/models/owner.rb
  2. +2
    -0
      app/models/user.rb

+ 2
- 0
app/models/owner.rb View File

@@ -69,6 +69,8 @@ class Owner < ApplicationRecord
has_many :applied_transfer_projects, dependent: :destroy

scope :like, lambda { |keywords|
# 表情处理
keywords = keywords.to_s.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?
}


+ 2
- 0
app/models/user.rb 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.to_s.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?
}


Loading…
Cancel
Save