debian-mirror-gitlab/app/models/projects/topic.rb

33 lines
995 B
Ruby
Raw Normal View History

2021-11-11 11:23:49 +05:30
# frozen_string_literal: true
2021-11-18 22:05:49 +05:30
require 'carrierwave/orm/activerecord'
2021-11-11 11:23:49 +05:30
module Projects
class Topic < ApplicationRecord
2021-11-18 22:05:49 +05:30
include Avatarable
include Gitlab::SQL::Pattern
2021-11-11 11:23:49 +05:30
validates :name, presence: true, uniqueness: true, length: { maximum: 255 }
2021-11-18 22:05:49 +05:30
validates :description, length: { maximum: 1024 }
2021-11-11 11:23:49 +05:30
has_many :project_topics, class_name: 'Projects::ProjectTopic'
has_many :projects, through: :project_topics
2021-11-18 22:05:49 +05:30
scope :order_by_total_projects_count, -> { order(total_projects_count: :desc).order(id: :asc) }
scope :reorder_by_similarity, -> (search) do
order_expression = Gitlab::Database::SimilarityScore.build_expression(search: search, rules: [
{ column: arel_table['name'] }
])
reorder(order_expression.desc, arel_table['total_projects_count'].desc, arel_table['id'])
end
class << self
def search(query)
fuzzy_search(query, [:name])
end
end
2021-11-11 11:23:49 +05:30
end
end
2021-12-11 22:18:48 +05:30
::Projects::Topic.prepend_mod_with('Projects::Topic')