mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
init project
This commit is contained in:
40
app/models/searchable/course.rb
Normal file
40
app/models/searchable/course.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
module Searchable::Course
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
searchkick language: 'chinese', callbacks: :async
|
||||
|
||||
scope :search_import, -> { includes(:teacher_users, teacher: { user_extension: :school } ) }
|
||||
end
|
||||
|
||||
def searchable_title
|
||||
name
|
||||
end
|
||||
|
||||
def search_data
|
||||
{
|
||||
laboratory_id: laboratory_id,
|
||||
name: name,
|
||||
author_name: teacher&.real_name
|
||||
}
|
||||
end
|
||||
|
||||
def to_searchable_json
|
||||
{
|
||||
id: id,
|
||||
author_name: teacher&.real_name,
|
||||
author_school_name: teacher&.school_name,
|
||||
visits_count: visits,
|
||||
members_count: course_members_count,
|
||||
tasks_count: homework_commons_count + exercises_count + polls_count,
|
||||
is_public: is_public == 1,
|
||||
first_category_url: ApplicationController.helpers.module_url(none_hidden_course_modules.first, self)
|
||||
}
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def searchable_includes
|
||||
{ teacher: { user_extension: :school } }
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/models/searchable/dependents.rb
Normal file
2
app/models/searchable/dependents.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Searchable::Dependents
|
||||
end
|
||||
16
app/models/searchable/dependents/challenge_tag.rb
Normal file
16
app/models/searchable/dependents/challenge_tag.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Searchable::Dependents::ChallengeTag
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_create_commit :check_searchable_dependents
|
||||
after_update_commit :check_searchable_dependents
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_searchable_dependents
|
||||
if new_record? || name_previously_changed?
|
||||
challenge.shixun.reindex
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/models/searchable/dependents/stage.rb
Normal file
15
app/models/searchable/dependents/stage.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Searchable::Dependents::Stage
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_update_commit :check_searchable_dependents
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_searchable_dependents
|
||||
if name_previously_changed? || description_previously_changed?
|
||||
subject.reindex
|
||||
end
|
||||
end
|
||||
end
|
||||
23
app/models/searchable/dependents/user.rb
Normal file
23
app/models/searchable/dependents/user.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module Searchable::Dependents::User
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_update_commit :check_searchable_dependents
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_searchable_dependents
|
||||
if firstname_previously_changed? || lastname_previously_changed? || user_extension&.school_id_previously_changed?
|
||||
# reindex shixun
|
||||
created_shixuns.each(&:reindex)
|
||||
|
||||
# reindex course
|
||||
manage_courses.each(&:reindex)
|
||||
|
||||
# reindex subject
|
||||
created_subjects.each(&:reindex)
|
||||
subjects.each(&:reindex)
|
||||
end
|
||||
end
|
||||
end
|
||||
47
app/models/searchable/memo.rb
Normal file
47
app/models/searchable/memo.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
module Searchable::Memo
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
searchkick language: 'chinese', callbacks: :async
|
||||
|
||||
scope :search_import, -> { includes(:descendants) }
|
||||
end
|
||||
|
||||
def searchable_title
|
||||
subject
|
||||
end
|
||||
|
||||
def should_index?
|
||||
hidden.zero? && root_id.blank? && parent_id.blank?
|
||||
end
|
||||
|
||||
def search_data
|
||||
{
|
||||
name: subject,
|
||||
content: Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH],
|
||||
}.merge!(searchable_descendants_data)
|
||||
end
|
||||
|
||||
def searchable_descendants_data
|
||||
{
|
||||
descendants_contents: Util.map_or_pluck(descendants, :content)
|
||||
.map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] }
|
||||
.join('<br/>')
|
||||
}
|
||||
end
|
||||
|
||||
def to_searchable_json
|
||||
{
|
||||
id: id,
|
||||
author_name: author.full_name,
|
||||
visits_count: viewed_count,
|
||||
all_replies_count: all_replies_count
|
||||
}
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def searchable_includes
|
||||
[:author]
|
||||
end
|
||||
end
|
||||
end
|
||||
68
app/models/searchable/shixun.rb
Normal file
68
app/models/searchable/shixun.rb
Normal file
@@ -0,0 +1,68 @@
|
||||
module Searchable::Shixun
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
searchkick language: 'chinese', callbacks: :async
|
||||
|
||||
scope :search_import, -> { includes(:shixun_info, :challenges, :challenge_tags, :users, user: { user_extension: :school }) }
|
||||
end
|
||||
|
||||
def searchable_title
|
||||
name
|
||||
end
|
||||
|
||||
def search_data
|
||||
{
|
||||
name: name,
|
||||
description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH],
|
||||
status: status,
|
||||
myshixuns_count: myshixuns_count,
|
||||
created_at: created_at,
|
||||
publish_time: publish_time,
|
||||
is_wechat_support: is_wechat_support
|
||||
}.merge!(searchable_user_data)
|
||||
.merge!(searchable_challenge_data)
|
||||
end
|
||||
|
||||
def searchable_user_data
|
||||
{
|
||||
author_name: user&.real_name,
|
||||
author_school_name: user&.school_name,
|
||||
}
|
||||
end
|
||||
|
||||
def searchable_challenge_data
|
||||
challenge_names = Util.map_or_pluck(challenges, :subject)
|
||||
.each_with_index.map { |subject, index| "第#{index + 1}关 #{subject}" }
|
||||
|
||||
{
|
||||
challenge_names: challenge_names.join(' '),
|
||||
challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ')
|
||||
}
|
||||
end
|
||||
|
||||
def should_index?
|
||||
!hidden? && [0, 1, 2].include?(status) # published
|
||||
end
|
||||
|
||||
def to_searchable_json
|
||||
{
|
||||
id: id,
|
||||
identifier: identifier,
|
||||
author_name: user.real_name,
|
||||
author_school_name: user.school_name,
|
||||
visits_count: visits,
|
||||
challenges_count: challenges_count,
|
||||
study_count: myshixuns_count,
|
||||
star: averge_star,
|
||||
level: shixun_level,
|
||||
is_jupyter: is_jupyter
|
||||
}
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def searchable_includes
|
||||
[ :shixun_info, user: { user_extension: :school } ]
|
||||
end
|
||||
end
|
||||
end
|
||||
62
app/models/searchable/subject.rb
Normal file
62
app/models/searchable/subject.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
module Searchable::Subject
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
searchkick language: 'chinese', callbacks: :async
|
||||
|
||||
scope :search_import, -> { includes(:users, :stages, user: { user_extension: :school }) }
|
||||
end
|
||||
|
||||
def searchable_title
|
||||
name
|
||||
end
|
||||
|
||||
def should_index?
|
||||
!hidden? && status == 2 # published
|
||||
end
|
||||
|
||||
def search_data
|
||||
{
|
||||
name: name,
|
||||
status: status,
|
||||
hidden: hidden,
|
||||
description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH],
|
||||
shixuns_count: shixuns_count,
|
||||
myshixuns_count: member_count,
|
||||
}.merge!(searchable_user_data)
|
||||
.merge!(searchable_stages_data)
|
||||
end
|
||||
|
||||
def searchable_user_data
|
||||
{
|
||||
author_name: user.real_name,
|
||||
author_school_name: user.school_name,
|
||||
member_user_names: users.map(&:real_name).join(' ')
|
||||
}
|
||||
end
|
||||
|
||||
def searchable_stages_data
|
||||
subject_stages = stages.map { |stage| "#{stage.name} #{Util.extract_content(stage.description)}"[0..Searchable::MAXIMUM_LENGTH] }
|
||||
|
||||
{ subject_stages: subject_stages.join('<br/>') }
|
||||
end
|
||||
|
||||
def to_searchable_json
|
||||
{
|
||||
id: id,
|
||||
author_name: user.real_name,
|
||||
author_school_name: user.school_name,
|
||||
visits_count: visits,
|
||||
stage_count: stages_count,
|
||||
stage_shixuns_count: stage_shixuns_count,
|
||||
shixuns_count: shixuns_count,
|
||||
myshixuns_count: member_count
|
||||
}
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def searchable_includes
|
||||
{ user: { user_extension: :school } }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user