forum: fix /forum_posts?search[linked_to] not normalizing tags.
Fix searches like https://danbooru.donmai.us/forum_posts?search[linked_to]=touhou%20 not working because the tag wasn't normalized.
This commit is contained in:
@@ -36,13 +36,17 @@ class ForumPost < ApplicationRecord
|
|||||||
where(topic_id: ForumTopic.visible(user))
|
where(topic_id: ForumTopic.visible(user))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wiki_link_matches(title)
|
||||||
|
where(id: DtextLink.forum_post.wiki_link.where(link_target: WikiPage.normalize_title(title)).select(:model_id))
|
||||||
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.search_attributes(params, :is_deleted, :body)
|
q = q.search_attributes(params, :is_deleted, :body)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
|
||||||
|
|
||||||
if params[:linked_to].present?
|
if params[:linked_to].present?
|
||||||
q = q.where(id: DtextLink.forum_post.wiki_link.where(link_target: params[:linked_to]).select(:model_id))
|
q = q.wiki_link_matches(params[:linked_to])
|
||||||
end
|
end
|
||||||
|
|
||||||
q.apply_default_order(params)
|
q.apply_default_order(params)
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
should respond_to_search(body_matches: "xxx").with { @forum_post }
|
should respond_to_search(body_matches: "xxx").with { @forum_post }
|
||||||
should respond_to_search(body_matches: "bababa").with { [] }
|
should respond_to_search(body_matches: "bababa").with { [] }
|
||||||
should respond_to_search(is_deleted: "true").with { @unrelated_forum }
|
should respond_to_search(is_deleted: "true").with { @unrelated_forum }
|
||||||
|
should respond_to_search(linked_to: "TEST").with { @other_forum }
|
||||||
|
|
||||||
context "using includes" do
|
context "using includes" do
|
||||||
should respond_to_search(topic: {title_matches: "my forum topic"}).with { @forum_post }
|
should respond_to_search(topic: {title_matches: "my forum topic"}).with { @forum_post }
|
||||||
|
|||||||
Reference in New Issue
Block a user