Fix #1898: Include alias predicates in non-empty Tags search.

Make searches on the /tags index includes aliases too. Show matching
aliases like this:

   Name: gray*

   ? 75098 grey_hair <- gray_hair
   ? 35345 grey_eyes <- gray_eyes
This commit is contained in:
evazion
2020-02-23 00:20:09 -06:00
parent a8e5412d9c
commit a181e6d0db
5 changed files with 26 additions and 1 deletions

View File

@@ -816,6 +816,14 @@ class Tag < ApplicationRecord
where_like(:name, normalize_name(name))
end
def alias_matches(name)
where(name: TagAlias.active.where_ilike(:antecedent_name, normalize_name(name)).select(:consequent_name))
end
def name_or_alias_matches(name)
name_matches(name).or(alias_matches(name))
end
def search(params)
q = super
@@ -833,6 +841,10 @@ class Tag < ApplicationRecord
q = q.where("tags.name": normalize_name(params[:name_normalize]).split(","))
end
if params[:name_or_alias_matches].present?
q = q.name_or_alias_matches(params[:name_or_alias_matches])
end
if params[:hide_empty].blank? || params[:hide_empty].to_s.truthy?
q = q.where("post_count > 0")
end