0
0
Fork 0

Implement UI for Admin Search of Hashtags (#30880)

This commit is contained in:
Emelia Smith 2024-07-29 17:49:44 +02:00 committed by GitHub
parent 6d2ed0dcba
commit c40e481169
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 316 additions and 11 deletions

View file

@ -52,6 +52,7 @@ class Tag < ApplicationRecord
scope :unreviewed, -> { where(reviewed_at: nil) }
scope :pending_review, -> { unreviewed.where.not(requested_review_at: nil) }
scope :usable, -> { where(usable: [true, nil]) }
scope :not_usable, -> { where(usable: false) }
scope :listable, -> { where(listable: [true, nil]) }
scope :trendable, -> { Setting.trendable_by_default ? where(trendable: [true, nil]) : where(trendable: true) }
scope :not_trendable, -> { where(trendable: false) }
@ -74,6 +75,10 @@ class Tag < ApplicationRecord
attributes['display_name'] || name
end
def formatted_name
"##{display_name}"
end
def usable
boolean_with_default('usable', true)
end
@ -132,8 +137,10 @@ class Tag < ApplicationRecord
def search_for(term, limit = 5, offset = 0, options = {})
stripped_term = term.strip
options.reverse_merge!({ exclude_unlistable: true, exclude_unreviewed: false })
query = Tag.listable.matches_name(stripped_term)
query = Tag.matches_name(stripped_term)
query = query.merge(Tag.listable) if options[:exclude_unlistable]
query = query.merge(matching_name(stripped_term).or(where.not(reviewed_at: nil))) if options[:exclude_unreviewed]
query.order(Arel.sql('length(name) ASC, name ASC'))