FIX: find tags with non-latin names (#6312)

This commit is contained in:
Maja Komel 2018-08-27 03:05:28 +02:00 committed by Sam
parent b760f66523
commit 020eba4623
2 changed files with 13 additions and 4 deletions

View File

@ -372,7 +372,7 @@ class Search
end
end
advanced_filter(/^\#([a-zA-Z0-9\-:=]+)/) do |posts, match|
advanced_filter(/^\#([\p{L}0-9\-:=]+)/) do |posts, match|
exact = true
@ -468,11 +468,11 @@ class Search
end
end
advanced_filter(/^tags?:([a-zA-Z0-9,\-_+]+)/) do |posts, match|
advanced_filter(/^tags?:([\p{L}0-9,\-_+]+)/) do |posts, match|
search_tags(posts, match, positive: true)
end
advanced_filter(/\-tags?:([a-zA-Z0-9,\-_+]+)/) do |posts, match|
advanced_filter(/\-tags?:([\p{L}0-9,\-_+]+)/) do |posts, match|
search_tags(posts, match, positive: false)
end

View File

@ -822,8 +822,9 @@ describe Search do
expect(Search.execute("sams post #sub-category").posts.length).to eq(1)
# tags
topic.tags = [Fabricate(:tag, name: 'alpha')]
topic.tags = [Fabricate(:tag, name: 'alpha'), Fabricate(:tag, name: 'привет')]
expect(Search.execute('this is a test #alpha').posts.map(&:id)).to eq([post.id])
expect(Search.execute('this is a test #привет').posts.map(&:id)).to eq([post.id])
expect(Search.execute('this is a test #beta').posts.size).to eq(0)
end
@ -864,6 +865,14 @@ describe Search do
expect(Search.execute('tags:plants').posts.size).to eq(0)
end
it 'can find posts with non-latin tag' do
topic = Fabricate(:topic)
topic.tags = [Fabricate(:tag, name: 'さようなら')]
post = Fabricate(:post, raw: 'Testing post', topic: topic)
expect(Search.execute('tags:さようなら').posts.map(&:id)).to eq([post.id])
end
it 'can find posts with any tag from multiple tags' do
Fabricate(:post)