mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
FEATURE: align with /filter and allow multiple category search (#27440)
This introduces the syntax of `category:a,b,c` which will search across multiple categories. Previously there was no way to allow search across a wide selection of categories.
This commit is contained in:
@ -1255,6 +1255,41 @@ RSpec.describe Search do
|
||||
)
|
||||
end
|
||||
|
||||
it "allow searching for multiple categories" do
|
||||
category2 = Fabricate(:category, name: "abc")
|
||||
topic2 = Fabricate(:topic, category: category2)
|
||||
post2 = Fabricate(:post, topic: topic2, raw: "snow monkey")
|
||||
|
||||
category3 = Fabricate(:category, name: "def")
|
||||
topic3 = Fabricate(:topic, category: category3)
|
||||
post3 = Fabricate(:post, topic: topic3, raw: "snow monkey")
|
||||
|
||||
search = Search.execute("monkey category:abc,def")
|
||||
expect(search.posts.map(&:id)).to contain_exactly(post2.id, post3.id)
|
||||
|
||||
search = Search.execute("monkey categories:abc,def")
|
||||
expect(search.posts.map(&:id)).to contain_exactly(post2.id, post3.id)
|
||||
|
||||
search = Search.execute("monkey categories:xxxxx,=abc,=def")
|
||||
expect(search.posts.map(&:id)).to contain_exactly(post2.id, post3.id)
|
||||
|
||||
search = Search.execute("snow category:abc,#{category.id}")
|
||||
expect(search.posts.map(&:id)).to contain_exactly(post.id, post2.id)
|
||||
|
||||
child_category = Fabricate(:category, parent_category: category2)
|
||||
child_topic = Fabricate(:topic, category: child_category)
|
||||
child_post = Fabricate(:post, topic: child_topic, raw: "snow monkey")
|
||||
|
||||
search = Search.execute("monkey category:zzz,nnn,=abc,mmm")
|
||||
expect(search.posts.map(&:id)).to contain_exactly(post2.id)
|
||||
|
||||
search =
|
||||
Search.execute(
|
||||
"monkey category:0007847874874874874748749398384398439843984938439843948394834984934839483984983498394834983498349834983,zzz,nnn,abc,mmm",
|
||||
)
|
||||
expect(search.posts.map(&:id)).to contain_exactly(post2.id, child_post.id)
|
||||
end
|
||||
|
||||
it "should return the right categories" do
|
||||
search = Search.execute("monkey")
|
||||
|
||||
|
Reference in New Issue
Block a user