Browse Source

Fixes #3876 - Duplicate results in search.

Rolf Schmidt 2 years ago
parent
commit
395c366c0b
2 changed files with 21 additions and 1 deletions
  1. 1 1
      app/models/ticket/search.rb
  2. 20 0
      spec/models/ticket/search_spec.rb

+ 1 - 1
app/models/ticket/search.rb

@@ -211,7 +211,7 @@ returns
 
                      tickets_all.joins(tables)
                                 .where(query_condition, *bind_condition)
-                   end.pluck(:id)
+                   end.group(:id).pluck(:id)
 
       if full
         ticket_ids.map { |id| Ticket.lookup(id: id) }

+ 20 - 0
spec/models/ticket/search_spec.rb

@@ -0,0 +1,20 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe Ticket::Search do
+  describe 'Duplicate results in search #3876' do
+    let(:search)   { SecureRandom.uuid }
+    let(:ticket)   { create(:ticket, group: Group.first) }
+    let(:articles) { create_list(:ticket_article, 3, ticket: ticket, body: search) }
+    let(:agent)    { create(:agent, groups: Group.all) }
+
+    before do
+      articles
+    end
+
+    it 'does not show up the same ticket twice if no elastic search is configured' do
+      expect(Ticket.search(current_user: agent, query: search)).to eq([ticket])
+    end
+  end
+end