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:
Sam
2024-06-12 16:06:04 +10:00
committed by GitHub
parent be4f1e3350
commit dc8249c08a
2 changed files with 71 additions and 10 deletions

View File

@ -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")