Fix: #370 ダブルクオートを使った日本語検索が効かない (#448)

* Fix: #370 ダブルクオートを使った日本語検索が効かない

* Add test for multiple words

* Improve test

* 入れ替え

* 単語検索のテスト
This commit is contained in:
KMY(雪あすか) 2024-01-12 10:27:35 +09:00 committed by GitHub
parent b044cbeb63
commit d864399a09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 4 deletions

View file

@ -213,4 +213,54 @@ describe StatusesSearchService do
end
end
end
describe 'a local user posts with search keyword' do
subject do
described_class.new.call(search_keyword, account, limit: 10).map(&:id)
end
let(:search_keyword) { 'ohagi' }
let(:status_text) { 'りんごを食べました' }
let(:alice) { Fabricate(:user).account }
let(:account) { alice }
let!(:status) { Fabricate(:status, text: status_text, account: alice, searchability: :public) }
before do
alice.update!(username: 'alice')
StatusesIndex.import!
end
shared_examples 'hit status' do |name, keyword|
context name do
let(:search_keyword) { keyword }
it 'a status hits' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end
end
shared_examples 'does not hit status' do |name, keyword|
context name do
let(:search_keyword) { keyword }
it 'no statuses hit' do
expect(subject.count).to eq 0
end
end
end
it_behaves_like 'hit status', 'when search with word', 'りんご'
it_behaves_like 'hit status', 'when search with multiple words', 'りんご 食べる'
it_behaves_like 'does not hit status', 'when search with multiple words but does not hit half', 'りんご 茹でる'
it_behaves_like 'hit status', 'when search with letter in word', 'ご'
it_behaves_like 'does not hit status', 'when double quote search with letter in word', '"ご"'
it_behaves_like 'hit status', 'when search with fixed word', '"りんご"'
it_behaves_like 'hit status', 'when double quote search with multiple letter in word', 'り ご'
it_behaves_like 'does not hit status', 'when double quote search with multiple letter in word but does not contain half', 'ず ご'
it_behaves_like 'hit status', 'when specify user name', 'りんご from:alice'
it_behaves_like 'does not hit status', 'when specify not existing user name', 'りんご from:ohagi'
end
end