From 94fd8c2957dbda689929ffe6a467b1b89f769e60 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 19 Nov 2019 09:03:46 +0100 Subject: [PATCH] Fixed issue #2809 - Array values (e.g. several states) nuke reporting profiles. --- lib/search_index_backend.rb | 5 +-- spec/lib/search_index_backend_spec.rb | 46 +++++++++++++++++++-------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 22d5ff366..eb59fbf95 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -448,6 +448,9 @@ example for aggregations within one year selector.each do |key, data| key_tmp = key.sub(/^.+?\./, '') wildcard_or_term = 'term' + if data['value'].is_a?(Array) + wildcard_or_term = 'terms' + end t = {} # use .keyword in case of compare exact values @@ -456,13 +459,11 @@ example for aggregations within one year data['value'].each do |value| next if !value.is_a?(String) || value !~ /[A-z]/ - wildcard_or_term = 'terms' key_tmp += '.keyword' break end elsif data['value'].is_a?(String) && /[A-z]/.match?(data['value']) key_tmp += '.keyword' - wildcard_or_term = 'term' end end diff --git a/spec/lib/search_index_backend_spec.rb b/spec/lib/search_index_backend_spec.rb index 10eed4fee..6224c8f19 100644 --- a/spec/lib/search_index_backend_spec.rb +++ b/spec/lib/search_index_backend_spec.rb @@ -171,6 +171,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do let(:ticket5) { create :ticket, title: 'phrase some_title5', state_id: 1 } let(:ticket6) { create :ticket, title: 'phrase some::title6', state_id: 1 } let(:ticket7) { create :ticket, title: 'some title7', state_id: 1 } + let(:ticket8) { create :ticket, title: 'sometitle', state_id: 1 } before do Ticket.destroy_all # needed to remove not created tickets @@ -187,6 +188,8 @@ RSpec.describe SearchIndexBackend, searchindex: true do described_class.add('Ticket', ticket6) travel 1.second described_class.add('Ticket', ticket7) + travel 1.second + described_class.add('Ticket', ticket8) described_class.refresh end @@ -274,7 +277,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do { field: 'created_at', # sort to verify result }) - expect(result).to eq({ count: 4, ticket_ids: [ticket7.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 5, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) end it 'finds records with containing not some title7' do @@ -283,7 +286,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'contains not', 'value' => 'some title7', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) end it 'finds records with containing not -' do @@ -292,7 +295,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'contains not', 'value' => 'some-title1', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s] }) end it 'finds records with containing not _' do @@ -301,7 +304,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'contains not', 'value' => 'some_title2', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) end it 'finds records with containing not ::' do @@ -311,7 +314,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'value' => 'some::title3', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) end it 'finds records with containing not 4' do @@ -321,7 +324,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'value' => 4, }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) end it 'finds records with containing not "4"' do @@ -330,7 +333,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'contains not', 'value' => '4', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) end end @@ -407,7 +410,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'is not', 'value' => 'phrase', }) - expect(result).to eq({ count: 7, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 8, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) end it 'finds records with is not some title7' do @@ -416,7 +419,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'is not', 'value' => 'some title7', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) end it 'finds records with is not -' do @@ -425,7 +428,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'is not', 'value' => 'some-title1', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket2.id.to_s] }) end it 'finds records with is not _' do @@ -434,7 +437,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'is not', 'value' => 'some_title2', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) end it 'finds records with is not ::' do @@ -443,7 +446,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'is not', 'value' => 'some::title3', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket2.id.to_s, ticket1.id.to_s] }) end it 'finds records with is not 4' do @@ -452,7 +455,7 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'operator' => 'is not', 'value' => 4, }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) end it 'finds records with is not "4"' do @@ -462,8 +465,23 @@ RSpec.describe SearchIndexBackend, searchindex: true do 'value' => '4', }) - expect(result).to eq({ count: 6, ticket_ids: [ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) + expect(result).to eq({ count: 7, ticket_ids: [ticket8.id.to_s, ticket7.id.to_s, ticket6.id.to_s, ticket5.id.to_s, ticket4.id.to_s, ticket3.id.to_s, ticket1.id.to_s] }) end + + it 'finds records with is not state_id ["4"] and title ["sometitle"]' do + result = described_class.selectors('Ticket', + 'state_id' => { + 'operator' => 'is not', + 'value' => ['4'], + }, + 'title' => { + 'operator' => 'is', + 'value' => ['sometitle'], + }) + + expect(result).to eq({ count: 1, ticket_ids: [ticket8.id.to_s] }) + end + end end end