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

This commit is contained in:
xxq250 2023-03-09 16:22:48 +08:00
parent d993df7df4
commit 6f7b40ec24
5 changed files with 18 additions and 7 deletions

View File

@ -8,14 +8,17 @@ class Organizations::ProjectsController < Organizations::BaseController
.joins(team_projects: {team: :team_users})
.where(team_users: {user_id: current_user.id}).to_sql
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result if params[:search].present?
# 表情处理
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
@projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present?
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
@projects = paginate(@projects)
end
def search
tip_exception("请输入搜索关键词") if params[:search].nil?
# 表情处理
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
public_projects_sql = @organization.projects.where(is_public: true).to_sql
private_projects_sql = @organization.projects
.where(is_public: false)
@ -23,7 +26,7 @@ class Organizations::ProjectsController < Organizations::BaseController
.where(team_users: {user_id: current_user.id}).to_sql
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
@projects = @projects.ransack(name_or_identifier_cont: params[:search]).result
@projects = @projects.ransack(name_or_identifier_cont: keywords).result
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
end

View File

@ -240,6 +240,8 @@ class Project < ApplicationRecord
end
def self.search_project(search)
# 表情处理
search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
ransack(name_or_identifier_cont: search)
end
# 创建者

View File

@ -53,7 +53,9 @@ class Projects::ListMyQuery < ApplicationQuery
projects = projects.sync_mirror
end
q = projects.ransack(name_or_identifier_cont: params[:search])
# 表情处理
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
q = projects.ransack(name_or_identifier_cont: keywords)
scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)

View File

@ -51,7 +51,9 @@ class Projects::ListQuery < ApplicationQuery
# items = items.where(id: @ids).by_name_or_identifier(params[:search])
items = items.where(id: @ids)
else
items = items.by_name_or_identifier(params[:search]).or(main_collection.where(user_id: Owner.like(params[:search]).pluck(:id)))
# 表情处理
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
items = items.by_name_or_identifier(keywords).or(main_collection.where(user_id: Owner.like(keywords).pluck(:id)))
end
items
end

View File

@ -75,6 +75,8 @@ class Api::V1::Users::Projects::ListService < ApplicationService
projects = projects.with_project_type(project_type)
# 表情处理
search = search.to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
q = projects.ransack(name_or_identifier_cont: search)
scope = q.result.includes(:project_category, :project_language,:owner, :repository, :has_pinned_users)