FIX: Don't ignore category in search when using category filters.
This commit is contained in:
parent
dafba62931
commit
64f20e7e7a
|
@ -392,6 +392,7 @@ class Search
|
||||||
Category.where('parent_category_id = ?', category_ids.first).pluck(:id)
|
Category.where('parent_category_id = ?', category_ids.first).pluck(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@category_filter_matched ||= true
|
||||||
posts.where("topics.category_id IN (?)", category_ids)
|
posts.where("topics.category_id IN (?)", category_ids)
|
||||||
else
|
else
|
||||||
posts.where("1 = 0")
|
posts.where("1 = 0")
|
||||||
|
@ -441,6 +442,8 @@ class Search
|
||||||
category_ids +=
|
category_ids +=
|
||||||
Category.where('parent_category_id = ?', category_id).pluck(:id)
|
Category.where('parent_category_id = ?', category_id).pluck(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@category_filter_matched ||= true
|
||||||
posts.where("topics.category_id IN (?)", category_ids)
|
posts.where("topics.category_id IN (?)", category_ids)
|
||||||
else
|
else
|
||||||
# try a possible tag match
|
# try a possible tag match
|
||||||
|
@ -804,7 +807,8 @@ class Search
|
||||||
.order("posts.post_number #{@order == :latest ? "DESC" : ""}")
|
.order("posts.post_number #{@order == :latest ? "DESC" : ""}")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
categories_ignored(posts)
|
posts = categories_ignored(posts) unless @category_filter_matched
|
||||||
|
posts
|
||||||
end
|
end
|
||||||
|
|
||||||
if @order == :latest || (@term.blank? && !@order)
|
if @order == :latest || (@term.blank? && !@order)
|
||||||
|
|
|
@ -420,6 +420,7 @@ describe Search do
|
||||||
let!(:ignored_category) do
|
let!(:ignored_category) do
|
||||||
Fabricate(:category,
|
Fabricate(:category,
|
||||||
name: "monkey Category 1",
|
name: "monkey Category 1",
|
||||||
|
slug: "test",
|
||||||
search_priority: Searchable::PRIORITIES[:ignore]
|
search_priority: Searchable::PRIORITIES[:ignore]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -432,6 +433,10 @@ describe Search do
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(search.posts).to contain_exactly(category.topic.first_post, post)
|
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
|
end
|
||||||
|
|
||||||
describe "with child categories" do
|
describe "with child categories" do
|
||||||
|
|
Loading…
Reference in New Issue