From 1bf188d7ac1663ea9a4ce93215798ac8a23f978e Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 6 Jul 2021 17:36:27 +0000 Subject: [PATCH] Fixes #3598 - Search results missing for users with two names within lastname. --- app/models/user/search_index.rb | 1 + spec/lib/search_index_backend_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/user/search_index.rb b/app/models/user/search_index.rb index d8a199a0a..b752bcfe6 100644 --- a/app/models/user/search_index.rb +++ b/app/models/user/search_index.rb @@ -6,6 +6,7 @@ class User def search_index_attribute_lookup(include_references: true) attributes = super + attributes['fullname'] = fullname attributes.delete('password') if include_references diff --git a/spec/lib/search_index_backend_spec.rb b/spec/lib/search_index_backend_spec.rb index 0e5167e06..cfce74658 100644 --- a/spec/lib/search_index_backend_spec.rb +++ b/spec/lib/search_index_backend_spec.rb @@ -27,7 +27,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do let(:record) { create :ticket } before do - described_class.add(record_type, record) + record.search_index_update_backend described_class.refresh end @@ -37,6 +37,21 @@ RSpec.describe SearchIndexBackend, searchindex: true do end end + context 'when search for user firstname + double lastname' do + let(:record_type) { 'User'.freeze } + let(:record) { create :user, login: 'a', email: 'a@a.de', firstname: 'AnFirst', lastname: 'ASplit Lastname' } + + before do + record.search_index_update_backend + described_class.refresh + end + + it 'finds user record' do + result = described_class.search('AnFirst ASplit Lastname', record_type, sort_by: ['updated_at'], order_by: ['desc']) + expect(result).to eq([{ id: record.id.to_s, type: record_type }]) + end + end + context 'for query with no results' do subject(:search) { described_class.search(query, index, limit: 3000) }