diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-13 12:11:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-13 12:11:55 +0300 |
commit | bc2f7ab125361e4180018b1b933f42a8709df356 (patch) | |
tree | cbdb7c268428bbf1bd1023cfd5865a530e91dc8f /app/models/projects | |
parent | 56a177ed56309f4742fe9f978adec394636bd7ca (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/projects')
-rw-r--r-- | app/models/projects/project_topic.rb | 2 | ||||
-rw-r--r-- | app/models/projects/topic.rb | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/app/models/projects/project_topic.rb b/app/models/projects/project_topic.rb index d4b456ef482..7021a48646a 100644 --- a/app/models/projects/project_topic.rb +++ b/app/models/projects/project_topic.rb @@ -3,6 +3,6 @@ module Projects class ProjectTopic < ApplicationRecord belongs_to :project - belongs_to :topic + belongs_to :topic, counter_cache: :total_projects_count end end diff --git a/app/models/projects/topic.rb b/app/models/projects/topic.rb index 468cce785e0..f3352ecc5ee 100644 --- a/app/models/projects/topic.rb +++ b/app/models/projects/topic.rb @@ -1,13 +1,30 @@ # frozen_string_literal: true +require 'carrierwave/orm/activerecord' + module Projects class Topic < ApplicationRecord include Avatarable + include Gitlab::SQL::Pattern validates :name, presence: true, uniqueness: true, length: { maximum: 255 } validates :description, length: { maximum: 1024 } has_many :project_topics, class_name: 'Projects::ProjectTopic' has_many :projects, through: :project_topics + + 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 end end |