From ffce95eeaf49e2a2fbafbc5be5bd8ef188fdea6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Mon, 21 Aug 2023 20:36:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=A9=A2=E9=97=9C=E9=8D=B5=E5=AD=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=A9=A2=E8=80=81=E5=B8=AB=E5=90=8D?= =?UTF-8?q?=E7=A8=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/asia_databases_controller.rb | 74 ++++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/app/controllers/asia_databases_controller.rb b/app/controllers/asia_databases_controller.rb index acd6ed1..e5cb889 100644 --- a/app/controllers/asia_databases_controller.rb +++ b/app/controllers/asia_databases_controller.rb @@ -345,20 +345,20 @@ class AsiaDatabasesController < ApplicationController render json: { 'success' => true }.to_json end def filter_keywords(asia_data,select_field,keywords) - member_fields = [] - file_fields = [] - link_fields = [] - if select_field == nil - asia_data = asia_data.where(:slug_title=>/#{gsub_invalid_character(keywords)}/) - elsif select_field == "member_profile" - ms = MemberProfile.all.select{|m| m.name.include?(keywords)} - asia_data = asia_data.where(:member_profile_id.in=>ms.map{|m| m.id}) - elsif member_fields.include?(select_field) - ms = MemberProfile.all.select{|m| m.name.include?(keywords)} - m_ids = ms.map{|m| m.id.to_s } - tmp_asia_data = asia_data.select{|p| (p.send("#{select_field.singularize}_ids") & m_ids).count != 0} - asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) - elsif select_field.split(".").count > 1 + # member_fields = [] + # file_fields = [] + # link_fields = [] + # if select_field == nil + # asia_data = asia_data.where(:slug_title=>/#{gsub_invalid_character(keywords)}/) + # elsif select_field == "member_profile" + # ms = MemberProfile.all.select{|m| m.name.include?(keywords)} + # asia_data = asia_data.where(:member_profile_id.in=>ms.map{|m| m.id}) + # elsif member_fields.include?(select_field) + # ms = MemberProfile.all.select{|m| m.name.include?(keywords)} + # m_ids = ms.map{|m| m.id.to_s } + # tmp_asia_data = asia_data.select{|p| (p.send("#{select_field.singularize}_ids") & m_ids).count != 0} + # asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) + if select_field.split(".").count > 1 relate_name = select_field.split(".").first field_name = select_field.split(".").last.gsub(/^\$+/, '') relate = relate_name.camelize.constantize @@ -388,22 +388,38 @@ class AsiaDatabasesController < ApplicationController elsif (asia_data.klass.fields[select_field].options[:type] == Integer rescue false) tmp_asia_data = asia_data.select{|p| p.send(select_field).to_s.include?(keywords)} asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) - elsif file_fields.include?(select_field) - file_field = select_field.camelize.constantize - ids1 = file_field.where(:file=>/#{gsub_invalid_character(keywords)}/).pluck(:id) - ids2 = file_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id) - ids = ids1 + ids2 - tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0} - asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) - elsif link_fields.include?(select_field) - link_field = select_field.camelize.constantize - ids1 = link_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id) - ids2 = link_field.where(:url=>/#{gsub_invalid_character(keywords)}/).pluck(:id) - ids = ids1 + ids2 - tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0} - asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) + # elsif file_fields.include?(select_field) + # file_field = select_field.camelize.constantize + # ids1 = file_field.where(:file=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + # ids2 = file_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + # ids = ids1 + ids2 + # tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0} + # asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) + # elsif link_fields.include?(select_field) + # link_field = select_field.camelize.constantize + # ids1 = link_field.where(:title=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + # ids2 = link_field.where(:url=>/#{gsub_invalid_character(keywords)}/).pluck(:id) + # ids = ids1 + ids2 + # tmp_asia_data = asia_data.select{|p| (p.send("#{select_field}_ids") & ids).count != 0} + # asia_data = asia_data.where(:id.in=>tmp_asia_data.map{|p| p.id}) else - asia_data = asia_data.where(select_field=>/#{gsub_invalid_character(keywords)}/) + if asia_data.klass == AsiaTeacher + asia_data = asia_data.any_of([ + { + select_field=> /#{gsub_invalid_character(keywords)}/ + },{ + teacher => /#{gsub_invalid_character(keywords)}/ + } + ]) + else + asia_data = asia_data.any_of([ + { + select_field=> /#{gsub_invalid_character(keywords)}/ + },{ + :asia_teacher_id.in => AsiaTeacher.where(teacher: /#{gsub_invalid_character(keywords)}/).pluck(:id) + } + ]) + end end return asia_data end