diff --git a/app/controllers/shixun_lists_controller.rb b/app/controllers/shixun_lists_controller.rb index c77da46e0..52682089c 100644 --- a/app/controllers/shixun_lists_controller.rb +++ b/app/controllers/shixun_lists_controller.rb @@ -1,5 +1,9 @@ class ShixunListsController < ApplicationController def index + # 去除开头标点符号 + @reg = /^[,。?:;‘’!“”—……、]/ + # 附件的替换 + @atta_reg = /!\[.*]\(\/api\/attachments\/\d+\)/ @results = ShixunSearchService.call(search_params, current_laboratory) end diff --git a/app/views/shixun_lists/index.json.jbuilder b/app/views/shixun_lists/index.json.jbuilder index 2507be68d..98e3025e5 100644 --- a/app/views/shixun_lists/index.json.jbuilder +++ b/app/views/shixun_lists/index.json.jbuilder @@ -4,19 +4,13 @@ json.shixun_list do json.array! @results.with_highlights(multiple: true) do |obj, highlights| json.merge! obj.to_searchable_json json.challenge_names obj.challenges.pluck(:subject) - - # 去除开头标点符号 - reg = /^[,。?:;‘’!“”—……、]/ - # 附件的替换 - atta_reg = /!\[.*]\(\/api\/attachments\/\d+\)/ - - highlights[:description]&.first&.sub!(reg, '') - highlights[:description]&.map{|des| des.gsub(atta_reg, '')} - highlights[:content]&.first&.sub!(reg, '') - highlights[:content]&.map{|des| des.gsub(atta_reg, '')} + highlights[:description]&.first&.sub!(@reg, '') + highlights[:description]&.map{|des| des.gsub(@atta_reg, '')} + highlights[:content]&.first&.sub!(@reg, '') + highlights[:content]&.map{|des| des.gsub(@atta_reg, '')} json.title highlights.delete(:name)&.join('...') || obj.searchable_title - json.description highlights[:description]&.join('...') || Util.extract_content(obj.description)[0..300]&.gsub(atta_reg, '') + json.description highlights[:description]&.join('...') || Util.extract_content(obj.description)[0..300]&.gsub(@atta_reg, '') json.pic url_to_avatar(obj) json.content highlights