diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index b36a76125..ab5c9ef5d 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 68a8d071d..54d6ac520 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 # 创建者 diff --git a/app/queries/projects/list_my_query.rb b/app/queries/projects/list_my_query.rb index 7e555b529..734956b98 100644 --- a/app/queries/projects/list_my_query.rb +++ b/app/queries/projects/list_my_query.rb @@ -58,8 +58,10 @@ class Projects::ListMyQuery < ApplicationQuery elsif params[:project_type].to_s === "sync_mirror" 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) diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 6b0843540..2b048bd87 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -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 diff --git a/app/services/api/v1/users/projects/list_service.rb b/app/services/api/v1/users/projects/list_service.rb index 8b3bffef0..47457c58c 100644 --- a/app/services/api/v1/users/projects/list_service.rb +++ b/app/services/api/v1/users/projects/list_service.rb @@ -73,8 +73,10 @@ class Api::V1::Users::Projects::ListService < ApplicationService end - projects = projects.with_project_type(project_type) + 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)