pools: add ability to search for pools linking to given tag.

Add ability to search for pools linking to a given tag in the pool
description. Example:

    https://danbooru.donmai.us/pools?search[linked_to]=touhou

(This isn't actually exposed in the UI to avoid cluttering the pool
search form with rarely used options.)

Pools with broken links can be found here:

    https://danbooru.donmai.us/dtext_links?search[has_linked_tag]=No&search[has_linked_wiki]=No&search[model_type]=Pool

Lays the groundwork for fixing #4629.
This commit is contained in:
evazion
2022-01-15 20:16:06 -06:00
parent c3c4f5a2a7
commit 33103f6dc4
10 changed files with 72 additions and 42 deletions

View File

@@ -15,6 +15,7 @@ class Pool < ApplicationRecord
after_save :create_version
deletable
has_dtext_links :description
scope :series, -> { where(category: "series") }
scope :collection, -> { where(category: "collection") }
@@ -37,7 +38,7 @@ class Pool < ApplicationRecord
end
def search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :name, :description, :post_ids)
q = search_attributes(params, :id, :created_at, :updated_at, :is_deleted, :name, :description, :post_ids, :dtext_links)
q = q.text_attribute_matches(:description, params[:description_matches])
if params[:post_tags_match]
@@ -48,6 +49,14 @@ class Pool < ApplicationRecord
q = q.name_matches(params[:name_matches])
end
if params[:linked_to].present?
q = q.linked_to(params[:linked_to])
end
if params[:not_linked_to].present?
q = q.not_linked_to(params[:not_linked_to])
end
case params[:category]
when "series"
q = q.series