FIX: Don't ignore category in search when using category filters.

This commit is contained in:
Guo Xiang Tan 2019-03-19 11:23:14 +08:00
parent dafba62931
commit 64f20e7e7a
2 changed files with 10 additions and 1 deletions

View File

@ -392,6 +392,7 @@ class Search
Category.where('parent_category_id = ?', category_ids.first).pluck(:id)
end
@category_filter_matched ||= true
posts.where("topics.category_id IN (?)", category_ids)
else
posts.where("1 = 0")
@ -441,6 +442,8 @@ class Search
category_ids +=
Category.where('parent_category_id = ?', category_id).pluck(:id)
end
@category_filter_matched ||= true
posts.where("topics.category_id IN (?)", category_ids)
else
# try a possible tag match
@ -804,7 +807,8 @@ class Search
.order("posts.post_number #{@order == :latest ? "DESC" : ""}")
end
else
categories_ignored(posts)
posts = categories_ignored(posts) unless @category_filter_matched
posts
end
if @order == :latest || (@term.blank? && !@order)

View File

@ -420,6 +420,7 @@ describe Search do
let!(:ignored_category) do
Fabricate(:category,
name: "monkey Category 1",
slug: "test",
search_priority: Searchable::PRIORITIES[:ignore]
)
end
@ -432,6 +433,10 @@ describe Search do
)
expect(search.posts).to contain_exactly(category.topic.first_post, post)
search = Search.execute("monkey #test")
expect(search.posts).to contain_exactly(ignored_category.topic.first_post)
end
describe "with child categories" do